home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume7 / 2.11news / part13 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  60.7 KB

  1. Subject:  v07i053:  2.11 News Source, Part03/09
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: seismo!rick (Rick Adams)
  6. Mod.sources: Volume 7, Issue 53
  7. Archive-name: 2.11news/Part13
  8.  
  9. # To extract, sh this file
  10. #
  11. #    news 2.11 source part 3 of 9
  12. #
  13. if test ! -d src
  14. then
  15.     mkdir src
  16. fi
  17. echo x - src/inews.c 1>&2
  18. sed 's/.//' >src/inews.c <<'*-*-END-of-src/inews.c-*-*'
  19. -/*
  20. - * This software is Copyright (c) 1986 by Rick Adams.
  21. - *
  22. - * Permission is hereby granted to copy, reproduce, redistribute or
  23. - * otherwise use this software as long as: there is no monetary
  24. - * profit gained specifically from the use or reproduction or this
  25. - * software, it is not sold, rented, traded or otherwise marketed, and
  26. - * this copyright notice is included prominently in any copy
  27. - * made.
  28. - *
  29. - * The author make no claims as to the fitness or correctness of
  30. - * this software for any use whatsoever, and it is provided as is. 
  31. - * Any use of this software is at the user's own risk.
  32. - *
  33. - * inews - insert, receive, and transmit news articles.
  34. - *
  35. - */
  36. -
  37. -#ifdef SCCSID
  38. -static char    *SccsId = "@(#)inews.c    2.69    10/30/86";
  39. -#endif /* SCCSID */
  40. -
  41. -#include "iparams.h"
  42. -#include <errno.h>
  43. -
  44. -#ifdef BSD4_2
  45. -# include <sys/dir.h>
  46. -# include <sys/file.h>
  47. -#else    /* !BSD4_2 */
  48. -# include "ndir.h"
  49. -# ifdef USG
  50. -# include <fcntl.h>
  51. -# endif /* USG */
  52. -# ifdef LOCKF
  53. -# include <unistd.h>
  54. -# endif /* LOCKF */
  55. -#endif /* !BSD4_2 */
  56. -/* local defines for inews */
  57. -
  58. -#define OPTION    0    /* pick up an option string */
  59. -#define STRING    1    /* pick up a string of arguments */
  60. -
  61. -#define UNKNOWN 0001    /* possible modes for news program */
  62. -#define UNPROC    0002    /* Unprocessed input */
  63. -#define PROC    0004    /* Processed input */
  64. -#define    CONTROL    0010    /* Control Message */
  65. -#define    CREATENG 0020    /* Create a new newsgroup */
  66. -
  67. -char    forgedname[NAMELEN];    /* A user specified -f option. */
  68. -int spool_news = FALSE;
  69. -extern char histline[];
  70. -/* Fake sys line in case they forget their own system */
  71. -struct srec dummy_srec = { "MEMEME", "", "all", "", "" };
  72. -
  73. -char *Progname = "inews";    /* used by xerror to identify failing program */
  74. -
  75. -struct {            /* options table. */
  76. -    char    optlet;        /* option character. */
  77. -    char    filchar;    /* if to pickup string, fill character. */
  78. -    int    flag;        /* TRUE if have seen this opt. */
  79. -    int    oldmode;    /* OR of legal input modes. */
  80. -    int    newmode;    /* output mode. */
  81. -    char    *buf;        /* string buffer */
  82. -} *optpt, options[] = { /*
  83. -optlet    filchar        flag    oldmode    newmode        buf    */
  84. -'t',    ' ',        FALSE,    UNPROC,    UNKNOWN,    header.title,
  85. -'n',    NGDELIM,    FALSE,    UNPROC,    UNKNOWN,    header.nbuf,
  86. -'d',    '\0',        FALSE,    UNPROC,    UNKNOWN,    header.distribution,
  87. -'e',    ' ',        FALSE,    UNPROC,    UNKNOWN,    header.expdate,
  88. -'p',    '\0',        FALSE,    UNKNOWN|PROC,    PROC,    filename,
  89. -'f',    '\0',        FALSE,    UNPROC,    UNKNOWN,    forgedname,
  90. -'F',    ' ',        FALSE,    UNPROC,    UNKNOWN,    header.followid,
  91. -'c',    ' ',        FALSE,    UNKNOWN,UNKNOWN,    header.ctlmsg,
  92. -'C',    ' ',        FALSE,    UNKNOWN,CREATENG,    header.ctlmsg,
  93. -#define hflag    options[9].flag
  94. -'h',    '\0',        FALSE,    UNPROC,    UNKNOWN,    filename,
  95. -#define oflag    options[10].flag
  96. -'o',    '\0',        FALSE,    UNPROC, UNKNOWN,    header.organization,
  97. -#define Mflag    options[11].flag
  98. -'M',    '\0',        FALSE,    UNPROC, UNKNOWN,    filename,
  99. -'a',    '\0',        FALSE,    UNPROC, UNKNOWN,    header.approved,
  100. -'U',    '\0',        FALSE,    PROC, PROC,        filename,
  101. -'S',    '\0',        FALSE,    UNKNOWN|PROC,     UNPROC,    filename,
  102. -'x',    '\0',        FALSE,    UNPROC, UNKNOWN,    not_here,
  103. -'r',    '\0',        FALSE,    UNPROC, UNKNOWN,    header.replyto,
  104. -'\0',    '\0',        0,    0,    0,        (char *)NULL
  105. -};
  106. -
  107. -FILE *mailhdr();
  108. -extern int errno;
  109. -
  110. -struct timeb Now;
  111. -
  112. -/*
  113. - *    Authors:
  114. - *        Matt Glickman    glickman@ucbarpa.Berkeley.ARPA
  115. - *        Mark Horton    mark@cbosgd.UUCP
  116. - *        Stephen Daniels    swd@mcnc.UUCP
  117. - *        Tom Truscott    trt@duke.UUCP
  118. - *        Rick Adams    rick@seismo.CSS.GOV
  119. - *    IHCC version adapted by:
  120. - *        Larry Marek    larry@ihuxf.UUCP
  121. - */
  122. -main(argc, argv)
  123. -int    argc;
  124. -register char **argv;
  125. -{
  126. -    int    state;        /* which type of argument to pick up    */
  127. -    int    tlen, len;    /* temps for string processing routine    */
  128. -    register char *ptr;    /* pointer to rest of buffer        */
  129. -    int    filchar;    /* fill character (state = STRING)    */
  130. -    char    *user = NULL, *home = NULL;    /* environment temps    */
  131. -    struct passwd    *pw;    /* struct for pw lookup            */
  132. -    struct group    *gp;    /* struct for group lookup        */
  133. -    register int    i;
  134. -    FILE    *mfd;        /* mail file file-descriptor        */
  135. -    char    cbuf[BUFLEN];    /* command buffer            */
  136. -
  137. -    /* uuxqt doesn't close all it's files */
  138. -    for (i = 3; !close(i); i++)
  139. -        ;
  140. -    /* set up defaults and initialize. */
  141. -    mode = UNKNOWN;
  142. -    infp = stdin;
  143. -    pathinit();
  144. -    ptr = rindex(*argv, '/');
  145. -    if (!ptr)
  146. -        ptr = *argv - 1;
  147. -    actfp = xfopen(ACTIVE, "r+");
  148. -#ifdef BSD4_2
  149. -    if (flock(fileno(actfp), LOCK_SH|LOCK_NB) < 0 && errno == EWOULDBLOCK)
  150. -#else    /* !BSD4_2 */
  151. -#ifdef    LOCKF
  152. -    if (lockf(fileno(actfp), F_TLOCK, 0) < 0 && errno == EAGAIN)
  153. -#else    /* !LOCKF */
  154. -    sprintf(bfr, "%s.lock", ACTIVE);
  155. -    if (LINK(ACTIVE,bfr) < 0 && errno == EEXIST)
  156. -#endif /* V7 */
  157. -#endif    /* !BSD4_2 */
  158. -        spool_news = TRUE;
  159. -    else {
  160. -#ifdef SPOOLNEWS
  161. -        if (argc > 1 && !strcmp(*(argv+1), "-S")) {
  162. -            argc--;
  163. -            argv++;
  164. -        } else
  165. -            spool_news = TRUE;
  166. -
  167. -#endif /* SPOOLNEWS */
  168. -#if !defined(BSD4_2) && !defined(LOCKF)
  169. -    (void) UNLINK(bfr);
  170. -#endif    /* !BSD4_2 && !LOCKF */
  171. -    }
  172. -    if (argc > 1 && !strcmp(*(argv+1), "-U")) {
  173. -        dounspool();
  174. -        /* NOT REACHED */
  175. -    }
  176. -
  177. -    if (!strncmp(ptr+1, "rnews", 5)) {
  178. -        mode = PROC;
  179. -        if (spool_news) {
  180. -            dospool((char *)NULL, FALSE);
  181. -            /* NOT REACHED */
  182. -        }
  183. -#ifdef NICENESS
  184. -        nice(NICENESS);
  185. -#endif /* NICENESS */
  186. -    } else
  187. -        if (argc < 2)
  188. -            goto usage;
  189. -
  190. -    state = OPTION;
  191. -    header.title[0] = header.nbuf[0] = filename[0] = '\0';
  192. -
  193. -    /* check for existence of special files */
  194. -    if (!rwaccess(ARTFILE)) {
  195. -        mfd = mailhdr((struct hbuf *)NULL, exists(ARTFILE) ? "Unwritable files!" : "Missing files!");
  196. -        if (mfd != NULL) {
  197. -#ifdef HIDDENNET
  198. -            fprintf(mfd,"System: %s.%s\n\nThere was a problem with %s!!\n", LOCALSYSNAME, FULLSYSNAME, ARTFILE);
  199. -#else /* !HIDDENNET */
  200. -            fprintf(mfd,"System: %s\n\nThere was a problem with %s!!\n", FULLSYSNAME, ARTFILE);
  201. -#endif /* !HIDDENNET */
  202. -            (void) sprintf(cbuf, "touch %s;chmod 666 %s", ARTFILE, ARTFILE);
  203. -            (void) system(cbuf);
  204. -            if (rwaccess(ARTFILE))
  205. -                fprintf(mfd, "The problem has been taken care of.\n");
  206. -            else
  207. -                fprintf(mfd, "Corrective action failed - check suid bits.\n");
  208. -            (void) mclose(mfd);
  209. -        }
  210. -    }
  211. -    if (!rwaccess(ACTIVE)) {
  212. -        mfd = mailhdr((struct hbuf *)NULL, exists(ACTIVE) ? "Unwritable files!" : "Missing files!");
  213. -        if (mfd != NULL) {
  214. -#ifdef HIDDENNET
  215. -            fprintf(mfd,"System: %s.%s\n\nThere was a problem with %s!!\n", LOCALSYSNAME, FULLSYSNAME, ARTFILE);
  216. -#else /* !HIDDENNET */
  217. -            fprintf(mfd, "System: %s\n\nThere was a problem with %s!!\n", FULLSYSNAME, ACTIVE);
  218. -#endif /* !HIDDENNET */
  219. -            (void) sprintf(cbuf, "touch %s;chmod 666 %s", ACTIVE, ACTIVE);
  220. -            (void) system(cbuf);
  221. -            if (rwaccess(ACTIVE))
  222. -                fprintf(mfd, "The problem has been taken care of.\n");
  223. -            else
  224. -                fprintf(mfd, "Corrective action failed - check suid bits.\n");
  225. -            (void) mclose(mfd);
  226. -        }
  227. -    }
  228. -    SigTrap = FALSE;    /* true if a signal has been caught */
  229. -    if (mode != PROC) {
  230. -        (void) signal(SIGHUP, onsig);
  231. -        (void) signal(SIGINT, onsig);
  232. -    }
  233. -    savmask = umask(N_UMASK);    /* set up mask */
  234. -    uid = getuid();
  235. -    gid = getgid();
  236. -    duid = geteuid();
  237. -    dgid = getegid();
  238. -    (void) ftime(&Now);
  239. -    if (uid == 0 && duid == 0) {
  240. -        /*
  241. -         * Must go through with this kludge since
  242. -         * some systems do not honor the setuid bit
  243. -         * when root invokes a setuid program.
  244. -         */
  245. -        if ((pw = getpwnam(NEWSUSR)) == NULL)
  246. -            xerror("Cannot get NEWSU pw entry");
  247. -
  248. -        duid = pw->pw_uid;
  249. -        if ((gp = getgrnam(NEWSGRP)) == NULL)
  250. -            xerror("Cannot get NEWSG gr entry");
  251. -        dgid = gp->gr_gid;
  252. -        (void) setgid(dgid);
  253. -        (void) setuid(duid);
  254. -    }
  255. -
  256. -#ifndef IHCC
  257. -    /*
  258. -     * We force the use of 'getuser()' to prevent forgery of articles
  259. -     * by just changing $LOGNAME
  260. -     */
  261. -    if (isatty(fileno(stderr))) {
  262. -        if ((user = getenv("USER")) == NULL)
  263. -            user = getenv("LOGNAME");
  264. -        if ((home = getenv("HOME")) == NULL)
  265. -            home = getenv("LOGDIR");
  266. -    }
  267. -#endif
  268. -    if (user == NULL || home == NULL)
  269. -        getuser();
  270. -    else {
  271. -        if (username == NULL || username[0] == 0) {
  272. -            username = AllocCpy(user);
  273. -        }
  274. -        userhome = AllocCpy(home);
  275. -    }
  276. -    getuser();
  277. -
  278. -    /* loop once per arg. */
  279. -
  280. -    ++argv;        /* skip first arg, which is prog name. */
  281. -
  282. -    while (--argc) {
  283. -        if (state == OPTION) {
  284. -        if (**argv != '-') {
  285. -            xerror("Bad option string \"%s\"", *argv);
  286. -        }
  287. -        while (*++*argv != '\0') {
  288. -            for (optpt = options; optpt->optlet != '\0'; ++optpt) {
  289. -                if (optpt->optlet == **argv)
  290. -                    goto found;
  291. -            }
  292. -            /* unknown option letter */
  293. -usage:
  294. -            fprintf(stderr, "usage: inews -t title");
  295. -            fprintf(stderr, " [ -n newsgroups ]");
  296. -            fprintf(stderr, " [ -e expiration date ]\n");
  297. -            fprintf(stderr, "\t[ -f sender]\n\n");
  298. -            xxit(1);
  299. -
  300. -            found:;
  301. -            if (optpt->flag == TRUE || (mode != UNKNOWN &&
  302. -                (mode&optpt->oldmode) == 0)) {
  303. -                xerror("Bad %c option", **argv);
  304. -            }
  305. -            if (mode == UNKNOWN)
  306. -                mode = optpt->newmode;
  307. -            filchar = optpt->filchar;
  308. -            optpt->flag = TRUE;
  309. -            state = STRING;
  310. -            ptr = optpt->buf;
  311. -            len = BUFLEN;
  312. -        }
  313. -
  314. -        argv++;        /* done with this option arg. */
  315. -
  316. -        } else {
  317. -
  318. -        /*
  319. -         * Pick up a piece of a string and put it into
  320. -         * the appropriate buffer.
  321. -         */
  322. -        if (**argv == '-') {
  323. -            state = OPTION;
  324. -            argc++;    /* uncount this arg. */
  325. -            continue;
  326. -        }
  327. -
  328. -        if ((tlen = strlen(*argv)) >= len)
  329. -            xerror("Argument string too long");
  330. -        (void) strcpy(ptr, *argv++);
  331. -        ptr += tlen;
  332. -        if (*(ptr-1) != filchar)
  333. -            *ptr++ = filchar;
  334. -        len -= tlen + 1;
  335. -        *ptr = '\0';
  336. -        }
  337. -    }
  338. -
  339. -    /*
  340. -     * ALL of the command line has now been processed. (!)
  341. -     */
  342. -
  343. -    if (*filename) {
  344. -        (void) fclose(stdin);
  345. -        infp = freopen(filename, "r", stdin);
  346. -        if (infp == NULL)
  347. -            xerror("freopen(%s): %s", filename, errmsg(errno));
  348. -    } else
  349. -        infp = stdin;
  350. -
  351. -    tty = isatty(fileno(infp));
  352. -
  353. -    if (mode == CREATENG)
  354. -        createng();
  355. -
  356. -    if (header.ctlmsg[0] != '\0' && header.title[0] == '\0')
  357. -        (void) strcpy(header.title, header.ctlmsg);
  358. -
  359. -    if (*header.nbuf) {
  360. -        lcase(header.nbuf);
  361. -        ptr = index(header.nbuf, '\0');
  362. -        if (ptr[-1] == NGDELIM)
  363. -            *--ptr = '\0';
  364. -    }
  365. -    (void) nstrip(header.title);
  366. -    (void) nstrip(header.expdate);
  367. -    (void) nstrip(header.followid);
  368. -    if (mode != PROC) {
  369. -        if (hflag) {
  370. -            header.path[0] = '\0';
  371. -            (void) hread(&header, infp, FALSE);
  372. -            /* there are certain fields we won't let him specify. */
  373. -            if (header.from[0])
  374. -                (void) strcpy(forgedname, header.from);
  375. -            if (!header.approved[0])
  376. -                Mflag = FALSE;
  377. -            header.from[0] = '\0';
  378. -            header.sender[0] = '\0';
  379. -            if (header.subdate[0] && cgtdate(header.subdate) < 0)
  380. -                header.subdate[0] = '\0';
  381. -        }
  382. -
  383. -        if (header.ident[0] == '\0')
  384. -            getident(&header);
  385. -
  386. -        if (forgedname[0]) {
  387. -            register char *p1;
  388. -            if (Mflag)
  389. -                sprintf(header.path, "%s!%s",
  390. -                    FULLSYSNAME, username);
  391. -            else if (!header.path[0]) {
  392. -                (void) strcpy(header.path, forgedname);
  393. -
  394. -                if ((p1 = strpbrk(header.path, "@ (<")) != NULL)
  395. -                    *p1 = '\0';
  396. -            }
  397. -            if (!Mflag && !strpbrk(forgedname, "@ (<"))
  398. -                (void) sprintf(header.from,"%s@%s%s",
  399. -                    forgedname, FULLSYSNAME, MYDOMAIN);
  400. -            else
  401. -                (void) strncpy(header.from, forgedname, BUFLEN);
  402. -
  403. -            (void) sprintf(header.sender, "%s@%s%s",
  404. -                username, FULLSYSNAME, MYDOMAIN);
  405. -        } else {
  406. -            gensender(&header, username);
  407. -        }
  408. -#ifdef MYORG
  409. -        if (header.organization[0] == '\0' && !Mflag &&
  410. -            header.sender[0] == '\0') {
  411. -            strncpy(header.organization, MYORG, BUFLEN);
  412. -            if (strncmp(header.organization, "Frobozz", 7) == 0)
  413. -                header.organization[0] = '\0';
  414. -            if (ptr = getenv("ORGANIZATION"))
  415. -                strncpy(header.organization, ptr, BUFLEN);
  416. -            /*
  417. -             * Note that the organization can also be turned off by
  418. -             * setting it to the null string, either in MYORG or
  419. -             * $ORGANIZATION in the environment.
  420. -             */
  421. -            if (header.organization[0] == '/') {
  422. -                mfd = fopen(header.organization, "r");
  423. -                if (mfd) {
  424. -                    (void) fgets(header.organization, sizeof header.organization, mfd);
  425. -                    (void) fclose(mfd);
  426. -                } else {
  427. -                    header.organization[0] = '\0';
  428. -                    logerr("Couldn't open %s",
  429. -                        header.organization);
  430. -                }
  431. -                ptr = index(header.organization, '\n');
  432. -                if (ptr)
  433. -                    *ptr = '\0';
  434. -            }
  435. -        }
  436. -#endif /* MYORG */
  437. -    }
  438. -
  439. -    /* Authorize newsgroups. */
  440. -    if (mode == PROC) {
  441. -#ifdef BATCH
  442. -        checkbatch();
  443. -#endif /* BATCH */
  444. -        (void) signal(SIGHUP, SIG_IGN);
  445. -        (void) signal(SIGINT, SIG_IGN);
  446. -        (void) signal(SIGQUIT, SIG_IGN);
  447. -        header.ident[0] = '\0';
  448. -        if (hread(&header, infp, TRUE) == NULL)
  449. -            error("Inbound news is garbled");
  450. -        input();
  451. -    }
  452. -    /* always check history */
  453. -
  454. -    if (history(&header)) {
  455. -        log("Duplicate article %s rejected. Path: %s",
  456. -            header.ident, header.path);
  457. -        xxit(0);
  458. -    }
  459. -
  460. -    /* Easy way to make control messages, since all.all.ctl is unblessed */
  461. -    if (mode != PROC && prefix(header.title, "cmsg ") && header.ctlmsg[0] == 0)
  462. -        (void) strcpy(header.ctlmsg, &header.title[5]);
  463. -    is_ctl = mode != CREATENG &&
  464. -        (ngmatch(header.nbuf, "all.all.ctl,") || header.ctlmsg[0]);
  465. -#ifdef DEBUG
  466. -    fprintf(stderr,"is_ctl set to %d\n", is_ctl);
  467. -#endif
  468. -
  469. -    if (mode != CREATENG) {
  470. -        if (!*header.title)
  471. -            error("No title, ng %s from %s", header.nbuf,
  472. -                header.from);
  473. -        if (!*header.nbuf)
  474. -            (void) strcpy(header.nbuf, DFLTNG);
  475. -    }
  476. -
  477. -    if (mode <= UNPROC) {
  478. -#ifdef FASCIST
  479. -        if (uid && uid != ROOTID && fascist(user, header.nbuf))
  480. -            xerror("User %s is not authorized to post to newsgroup %s",
  481. -                user, header.nbuf);
  482. -#endif /* FASCIST */
  483. -        ctlcheck();
  484. -    }
  485. -
  486. -    if (mode == CREATENG)
  487. -        createng();
  488. -
  489. -    /* Determine input. */
  490. -    if (mode != PROC)
  491. -        input();
  492. -    if (header.intnumlines == 0 && !is_ctl)
  493. -        error("%s rejected: no text lines", header.ident);
  494. -
  495. -    dates(&header);
  496. -
  497. -    /* Do the actual insertion. */
  498. -    insert();
  499. -}
  500. -
  501. -dospool(batchcmd, dolhwrite)
  502. -char *batchcmd;
  503. -int dolhwrite;
  504. -{
  505. -    register int c;
  506. -    register FILE *sp;
  507. -    register struct tm *tp;
  508. -    time_t t;
  509. -    char buf[BUFLEN];
  510. -    extern struct tm *gmtime();
  511. -
  512. -    (void) time(&t);
  513. -    tp = gmtime(&t);
  514. -    /* This file name "has to" be unique  (right?) */
  515. -#ifdef USG
  516. -    (void) sprintf(buf, "%s/.rnews/%2.2d%2.2d%2.2d%2.2d%2.2d%x",
  517. -#else
  518. -#ifdef VMS
  519. -    /* Eunice doesn't like dots in directory names */
  520. -    (void) sprintf(buf, "%s/+rnews/%02d%02d%02d%02d%02d%x",
  521. -#else /* V7 */
  522. -    (void) sprintf(buf, "%s/.rnews/%02d%02d%02d%02d%02d%x",
  523. -#endif /* V7 */
  524. -#endif /* VMS */
  525. -        SPOOLDIR,
  526. -        tp->tm_year, tp->tm_mon+1, tp->tm_mday,
  527. -        tp->tm_hour, tp->tm_min, getpid());
  528. -    sp = xfopen(buf, "w");
  529. -    if (batchcmd != NULL)
  530. -        fprintf(sp, "%s\n", batchcmd);
  531. -    if (dolhwrite)
  532. -        lhwrite(&header, sp);
  533. -    while ((c = getc(infp)) != EOF)
  534. -        putc(c, sp);
  535. -    fclose(sp);
  536. -    xxit(0);
  537. -    /* NOTREACHED */
  538. -}
  539. -
  540. -/*
  541. - *    Create a newsgroup
  542. - */
  543. -createng()
  544. -{
  545. -    register char *cp;
  546. -
  547. -    /*
  548. -     * Only certain users are allowed to create newsgroups
  549. -     */
  550. -    if (uid != ROOTID && uid != duid && uid) {
  551. -        fprintf(stderr, "Please contact one of the local netnews people\n\tto create this group for you");
  552. -        xxit(1);
  553. -    }
  554. -    if (header.distribution[0] == '\0')
  555. -#ifdef ORGDISTRIB
  556. -        strcpy(header.distribution, ORGDISTRIB);
  557. -#else /* !ORGDISTRIB */
  558. -        strcpy(header.distribution, "local");
  559. -#endif /* !ORGDISTRIB */
  560. -
  561. -    (void) strcpy(header.nbuf, header.ctlmsg);
  562. -    if ((cp=index(header.nbuf, ' ')) != NULL)
  563. -        *cp = '\0';
  564. -
  565. -    if (header.approved[0] == '\0')
  566. -        (void) sprintf(header.approved, "%s@%s%s",
  567. -                username, FULLSYSNAME, MYDOMAIN);
  568. -    (void) sprintf(bfr, "%s/inews -n %s.ctl -c newgroup %s -d %s -a \"%s\"",
  569. -        LIB, header.nbuf, header.ctlmsg, header.distribution,
  570. -        header.approved);
  571. -    if (tty) {
  572. -        printf("Please type in a paragraph describing the new newsgroup.\n");
  573. -        printf("End with control D as usual.\n");
  574. -    }
  575. -    printf("%s\n", bfr);
  576. -    (void) fflush(stdout);
  577. -    (void) system(bfr);
  578. -    exit(0);
  579. -    /*NOTREACHED*/
  580. -}
  581. -
  582. -char firstbufname[BUFLEN];
  583. -/*
  584. - *    Link ARTICLE into dir for ngname and update active file.
  585. - */
  586. -long
  587. -localize(ngname)
  588. -char    *ngname;
  589. -{
  590. -    char afline[BUFLEN];
  591. -    long ngsize;
  592. -    long fpos;
  593. -    int e;
  594. -    char *cp;
  595. -
  596. -    lock();
  597. -    (void) rewind(actfp); clearerr(actfp);
  598. -
  599. -    for(;;) {
  600. -        fpos = ftell(actfp);
  601. -        if (fgets(afline, sizeof afline, actfp) == NULL) {
  602. -            unlock();
  603. -            logerr("Can't find \"%s\" in active file", ngname);
  604. -            return FALSE;        /* No such newsgroup locally */
  605. -        }
  606. -        if (prefix(afline, ngname)) {
  607. -            (void) sscanf(afline, "%s %ld", bfr, &ngsize);
  608. -            if (strcmp(bfr, ngname) == 0) {
  609. -                if (ngsize < 0 || ngsize > 99998) {
  610. -                    logerr("found bad ngsize %ld ng %s, setting to 1", ngsize, bfr);
  611. -                    ngsize = 1;
  612. -                }
  613. -                break;
  614. -            }
  615. -        }
  616. -    }
  617. -    for (;;) {
  618. -        cp = dirname(ngname);
  619. -
  620. -        (void) sprintf(bfr, "%s/%ld", cp, ngsize+1);
  621. -#ifdef VMS
  622. -        /*
  623. -         * The effect of this code is to store the article in the first
  624. -         * newsgroup's directory and to put symbolic links elsewhere.
  625. -         * If this is the first group, firstbufname is not yet filled
  626. -         * in. It should be portable to other link-less systems.
  627. -         * epimass!jbuck
  628. -         */
  629. -        if (firstbufname[0]) {
  630. -            if (vmslink(firstbufname, bfr) == 0)
  631. -                break;
  632. -        } else if (rename(ARTICLE, bfr) == 0)
  633. -            break;
  634. -#else /* !VMS */
  635. -        if (link(ARTICLE, bfr) == 0)
  636. -            break;
  637. -#endif /* !VMS */
  638. -        if (!exists(cp))
  639. -            mknewsg(cp, ngname);
  640. -#ifdef VMS
  641. -        if (firstbufname[0]) {
  642. -            if (vmslink(firstbufname, bfr) == 0)
  643. -                break;
  644. -        } else if (rename(ARTICLE, bfr) == 0) 
  645. -            break;
  646. -#else /* !VMS */
  647. -        if (link(ARTICLE, bfr) == 0)
  648. -            break;
  649. -#endif /* !VMS */
  650. -        e = errno;    /* keep log from clobbering it */
  651. -        log("Cannot install article as %s: %s", bfr, errmsg(errno));
  652. -        if (e != EEXIST) {
  653. -            logerr("Link into %s failed (%s); check dir permissions.",
  654. -                bfr, errmsg(e));
  655. -            unlock();
  656. -            return FALSE;
  657. -        }
  658. -        ngsize++;
  659. -    }
  660. -
  661. -    /*
  662. -     * This works around a bug in the 4.1bsd stdio
  663. -     * on fseeks to non even offsets in r+w files
  664. -     */
  665. -    if (fpos&1)
  666. -        (void) rewind(actfp);
  667. -
  668. -    (void) fseek(actfp, fpos, 0);
  669. -#ifdef USG
  670. -    /*
  671. -     * U G L Y   K L U D G E
  672. -     * This utter piece of tripe is the only way I know of to get
  673. -     * around the fact that ATT BROKE standard IO in System 5.2.
  674. -     * Basically, you can't open a file for "r+" and then try and
  675. -     * write to it. This works on all "real" USGUnix systems, It will
  676. -     * probably break on some obscure look alike that doesnt use the
  677. -     * real ATT stdio.h
  678. -     * Don't blame me, blame ATT. stdio should have already done the
  679. -     * following line for us, but it doesn't
  680. -     */
  681. -     actfp->_flag |= _IOWRT;
  682. -#endif /* USG */
  683. -    /* Has to be same size as old because of %05d.
  684. -     * This will overflow with 99999 articles.
  685. -     */
  686. -    fprintf(actfp, "%s %05ld", ngname, ngsize+1);
  687. -    (void) fflush(actfp);
  688. -    if (ferror(actfp))
  689. -        xerror("Active file write failed");
  690. -    unlock();
  691. -    if (firstbufname[0] == '\0')
  692. -        (void) strcpy(firstbufname, bfr);
  693. -    (void) sprintf(bfr, "%s/%ld ", ngname, ngsize+1);
  694. -    addhist(bfr);
  695. -    return ngsize+1;
  696. -}
  697. -
  698. -/*
  699. - *    Localize for each newsgroup and broadcast.
  700. - */
  701. -insert()
  702. -{
  703. -    register char *ptr;
  704. -    register FILE *tfp;
  705. -    register int c;
  706. -    struct srec srec;    /* struct for sys file lookup    */
  707. -    struct tm *tm, *gmtime();
  708. -    int is_invalid = FALSE;
  709. -    int exitcode = 0;
  710. -    long now;
  711. -#ifdef DOXREFS
  712. -    register char *nextref = header.xref;
  713. -#endif /* DOXREFS */
  714. -
  715. -    /* Clean up Newsgroups: line */
  716. -    if (!is_ctl && mode != CREATENG)
  717. -        is_invalid = ngfcheck(mode == PROC);
  718. -
  719. -    (void) time(&now);
  720. -    tm = gmtime(&now);
  721. -    if (header.expdate[0])
  722. -        addhist(" ");
  723. -#ifdef USG
  724. -    sprintf(bfr,"%2.2d/%2.2d/%d %2.2d:%2.2d\t",
  725. -#else /* !USG */
  726. -    sprintf(bfr,"%02d/%02d/%d %02d:%02d\t",
  727. -#endif /* !USG */
  728. -        tm->tm_mon+1, tm->tm_mday, tm->tm_year,tm->tm_hour, tm->tm_min);
  729. -    addhist(bfr);
  730. -    log("%s %s ng %s subj '%s' from %s",
  731. -        spool_news ? "queued" : (mode==PROC ? "received" : "posted"),
  732. -        header.ident, header.nbuf, header.title, header.from);
  733. -
  734. -    /* Write article to temp file. */
  735. -    tfp = xfopen(mktemp(ARTICLE), "w");
  736. -
  737. -    if (is_invalid) {
  738. -        logerr("No valid newsgroups found, moved to junk");
  739. -        if (localize("junk"))
  740. -            savehist(histline);
  741. -        exitcode = 1;
  742. -        goto writeout;
  743. -    }
  744. -
  745. -#ifdef ZAPNOTES
  746. -    if (strcmp(header.title, "Re: Orphaned Response") == 0) {
  747. -        logerr("Orphaned Response, moved to junk");
  748. -        if (localize("junk"))
  749. -            savehist(histline);
  750. -        exitcode = 1;
  751. -        goto writeout;
  752. -    }
  753. -#endif    /* ZAPNOTES */
  754. -
  755. -    if (time((time_t *)0) > (cgtdate(header.subdate) + HISTEXP) ){
  756. -        logerr("Article too old, moved to junk");
  757. -        if (localize("junk"))
  758. -            savehist(histline);
  759. -        exitcode = 1;
  760. -        goto writeout;
  761. -    }
  762. -
  763. -    if (is_mod[0] != '\0'     /* one of the groups is moderated */
  764. -        && header.approved[0] == '\0') { /* and unapproved */
  765. -        struct hbuf mhdr;
  766. -        FILE *mfd;
  767. -        register char *p;
  768. -        char modadd[BUFLEN];
  769. -#ifdef DONTFOWARD
  770. -        if(mode == PROC) {
  771. -            logerr("Unapproved article in moderated group %s",
  772. -                is_mod);
  773. -            if (localize("junk"))
  774. -                savehist(histline);
  775. -            goto writeout;
  776. -        }
  777. -#endif /* DONTFORWARD */
  778. -        fprintf(stderr,"%s is moderated and may not be posted to",
  779. -            is_mod);
  780. -        fprintf(stderr," directly.\nYour article is being mailed to");
  781. -        fprintf(stderr," the moderator who will post it for you.\n");
  782. -        /* Let's find a path to the backbone */
  783. -        sprintf(bfr, "%s/mailpaths", LIBDIR);
  784. -        mfd = xfopen(bfr, "r");
  785. -        do {
  786. -            if (fgets(bfr, sizeof bfr, mfd) == NULL)
  787. -                xerror("Can't find backbone in %s/mailpaths",
  788. -                    LIBDIR);
  789. -        } while (!prefix(bfr, "backbone"));
  790. -        if (sscanf(bfr, "%*s %s", modadd) != 1)
  791. -            xerror("backbone address corrupted");
  792. -        /* fake a header for mailhdr */
  793. -        mhdr.from[0] = '\0';
  794. -        mhdr.replyto[0] = '\0';
  795. -        p = is_mod;
  796. -        while (*++p)
  797. -            if (*p == '.')
  798. -                *p = '-';
  799. -        sprintf(bfr, "Submission for %s", is_mod);
  800. -        sprintf(mhdr.path, modadd, is_mod);
  801. -        mfd = mailhdr(&mhdr, bfr);
  802. -        if (mfd == NULL)
  803. -            xerror("Can't send mail to %s", mhdr.path);
  804. -        lhwrite(&header, mfd);
  805. -        while ((c = getc(infp)) != EOF)
  806. -            putc(c, mfd);
  807. -        mclose(mfd);
  808. -        log("Article mailed to %s", mhdr.path);
  809. -        xxit(0);
  810. -    }
  811. -
  812. -    if (spool_news && mode != PROC) {
  813. -        fprintf(stderr,"Your article has been spooled for later processing.\n");
  814. -        dospool((char *)NULL, TRUE);
  815. -        /* NOT REACHED */
  816. -    }
  817. -
  818. -    if (is_ctl) {
  819. -        exitcode = control(&header);
  820. -        if (localize("control") && exitcode != 0)
  821. -            savehist(histline);
  822. -    } else {
  823. -        if (s_find(&srec, FULLSYSNAME) == FALSE) {
  824. -            logerr("Cannot find my name '%s' in %s", FULLSYSNAME, SUBFILE);
  825. -            srec = dummy_srec;
  826. -        }
  827. -#ifdef DOXREFS
  828. -        (void) strncpy(nextref, FULLSYSNAME, BUFLEN);
  829. -#endif /* DOXREFS */
  830. -        for (ptr = nbuf; *ptr;) {
  831. -            if (ngmatch(ptr,srec.s_nbuf) || index(ptr,'.') == NULL){
  832. -#ifdef DOXREFS
  833. -                while (*nextref++)
  834. -                    ;
  835. -                (void) sprintf(--nextref, " %s:%ld", ptr, localize(ptr));
  836. -#else /* !DOXREFS */
  837. -                (void) localize(ptr);
  838. -#endif /* !DOXREFS */
  839. -            }
  840. -            while (*ptr++)
  841. -                ;
  842. -        }
  843. -        if (firstbufname[0] == '\0') {
  844. -            logerr("Newsgroups in active, but not sys");
  845. -            (void) localize("junk");
  846. -        }
  847. -    }
  848. -#ifdef DOXREFS
  849. -    if (index(header.nbuf, NGDELIM) == NULL)
  850. -        header.xref[0] = '\0';
  851. -#endif /* DOXREFS */
  852. -
  853. -writeout:
  854. -    /* Part 1 of kludge to get around article truncation problem */
  855. -    if ( (c=getc(infp)) != EOF) {
  856. -        ungetc(c, infp);
  857. -        if (c == ' ' || c == '\t') {
  858. -            header.intnumlines++;
  859. -            (void) sprintf(header.numlines, "%d",
  860. -                header.intnumlines);
  861. -        }
  862. -    }
  863. -    /* End of part 1 */
  864. -    if (header.expdate[0] != '\0' && mode != PROC) {
  865. -        /* Make sure it's fully qualified */
  866. -        long t = cgtdate(header.expdate);
  867. -        strcpy(header.expdate, arpadate(&t));
  868. -    }
  869. -
  870. -    lhwrite(&header, tfp);
  871. -    if ((c = getc(infp)) != EOF) {
  872. -        /* Part 2 of kludge to get around article truncation problem */
  873. -        if (c == ' ' || c == '\t' )
  874. -            putc('\n', tfp);
  875. -        /* End of part 2 */
  876. -        ungetc(c, infp);
  877. -        while (fgets(bfr, BUFLEN, infp) != NULL)
  878. -            fputs(bfr, tfp);
  879. -        if (bfr[strlen(bfr)-1] != '\n')
  880. -            putc('\n',tfp);
  881. -    }
  882. -    if (ferror(tfp))
  883. -        xerror("Write failed for temp file");
  884. -    (void) fclose(tfp);
  885. -    (void) fclose(infp);
  886. -    if(exitcode == 0) {
  887. -        int pid;
  888. -        /* article has passed all the checks, so work in background */
  889. -        if (mode != PROC)
  890. -            if ((pid=vfork()) < 0)
  891. -                xerror("Can't fork");
  892. -            else if (pid > 0)
  893. -                exit(0);
  894. -#ifdef SIGTTOU
  895. -        signal(SIGTTOU, SIG_IGN);
  896. -#endif /* SIGTTOU */
  897. -        savehist(histline);
  898. -        broadcast();
  899. -    }
  900. -    xxit(mode == PROC ? 0 : exitcode);
  901. -}
  902. -
  903. -input()
  904. -{
  905. -    register char *cp;
  906. -    register int c;
  907. -    register int empty = TRUE;
  908. -    FILE *tmpfp;
  909. -    int consec_newlines = 0;
  910. -    int linecount = 0;
  911. -    int linserted = 0;
  912. -
  913. -    tmpfp = xfopen(mktemp(INFILE), "w");
  914. -    while (!SigTrap && fgets(bfr, BUFLEN, infp) != NULL) {
  915. -         if (mode == PROC) {    /* zap trailing empty lines */
  916. -#ifdef ZAPNOTES
  917. -            if (empty && bfr[0] == '#' && bfr[2] == ':'
  918. -                && header.nf_id[0] == '\0'
  919. -                && header.nf_from[0] == '\0' ) {
  920. -                (void) strcpy(header.nf_id, bfr);
  921. -                (void) nstrip(header.nf_id);
  922. -                (void) fgets(bfr, BUFLEN, infp);
  923. -                (void) strcpy(header.nf_from, bfr);
  924. -                (void) nstrip(header.nf_from);
  925. -                (void) fgets(bfr, BUFLEN, infp);
  926. -
  927. -                if (header.numlines[0]) {
  928. -                    header.intnumlines -= 2;
  929. -                    (void) sprintf(header.numlines, "%d", header.intnumlines);
  930. -                }
  931. -
  932. -                /* Strip trailing " - (nf)" */
  933. -                if ((cp = rindex(header.title, '-')) != NULL
  934. -                    && !strcmp(--cp, " - (nf)"))
  935. -                    *cp = '\0';
  936. -                log("Stripped notes header on %s", header.ident);
  937. -                continue;
  938. -            }
  939. -#endif /* ZAPNOTES */
  940. -             if (bfr[0] == '\n' ||
  941. -                /* Bandage for older versions of inews */
  942. -                bfr[1] == '\n' && !isascii(bfr[0])) {
  943. -                 consec_newlines++;    /* count it, in case */
  944. -                 continue;        /* but don't write it*/
  945. -             }
  946. -             /* foo! a non-empty line. write out all saved lines. */
  947. -             while (consec_newlines > 0) {
  948. -                putc('\n', tmpfp);
  949. -                consec_newlines--;
  950. -                linecount++;
  951. -            }
  952. -         }
  953. -        if (mode != PROC && tty && strcmp(bfr, ".\n") == 0)
  954. -            break;
  955. -        for (cp = bfr; c = toascii(*cp); cp++) {
  956. -            if (isprint(c) || isspace(c) || c == '\b')
  957. -                putc(c, tmpfp);
  958. -            if (c == '\n')
  959. -                linecount++;
  960. -        }
  961. -        if (bfr[0] == '>')
  962. -            linserted++;
  963. -        empty = FALSE;
  964. -    }
  965. -    if (*filename)
  966. -        (void) fclose(infp);
  967. -    if (mode != PROC && linserted > (linecount-linserted))
  968. -        error("Article rejected: %s included more text than new text",
  969. -            username);
  970. -
  971. -    if (mode != PROC && !is_ctl && header.sender[0] == '\0') {
  972. -        int siglines = 0;
  973. -        char sbuf[BUFLEN];
  974. -        (void) sprintf(bfr, "%s/%s", userhome, ".signature");
  975. -        if (access(bfr, 4) == 0) {
  976. -            if ((infp = fopen(bfr, "r")) == NULL) {
  977. -                (void) fprintf(stderr,
  978. -    "inews: \"%s\" left off (must be readable by \"inews\" owner)\n", bfr);
  979. -                goto finish;
  980. -            }
  981. -
  982. -            while (fgets(sbuf, sizeof sbuf, infp) != NULL)
  983. -                if (++siglines > 4)
  984. -                    break;
  985. -            if (siglines > 4)
  986. -                fprintf(stderr,".signature not included (> 4 lines)\n");
  987. -            else {
  988. -                rewind(infp);
  989. -                fprintf(tmpfp, "-- \n");    /* To separate */
  990. -                linecount++;
  991. -                while ((c = getc(infp)) != EOF) {
  992. -                    putc(c, tmpfp);
  993. -                    if (c == '\n')
  994. -                        linecount++;
  995. -                }
  996. -            }
  997. -            (void) fclose(infp);
  998. -        }
  999. -    }
  1000. -
  1001. -finish:
  1002. -    if (ferror(tmpfp))
  1003. -        xerror("write failed to temp file");
  1004. -    (void) fclose(tmpfp);
  1005. -    if (SigTrap) {
  1006. -        if (tty)
  1007. -            fprintf(stderr, "Interrupt\n");
  1008. -        if (tty && !empty)
  1009. -            fwait(fsubr(newssave, (char *) NULL, (char *) NULL));
  1010. -        if (!tty)
  1011. -            log("Blown away by an interrupt %d", SigTrap);
  1012. -        xxit(1);
  1013. -    }
  1014. -    if (tty)
  1015. -        fprintf(stderr, "EOT\n");
  1016. -    fflush(stdout);
  1017. -    infp = fopen(INFILE, "r");
  1018. -    if (header.numlines[0]) {
  1019. -        /*
  1020. -         * Check line count if there's already one attached to
  1021. -         * the article.  Could make this a fatal error -
  1022. -         * throwing it away if it got chopped, in hopes that
  1023. -         * another copy will come in later with a correct
  1024. -         * line count.  But that seems a bit much for now.
  1025. -         */
  1026. -        if (linecount != header.intnumlines) {
  1027. -            if (linecount == 0)
  1028. -                error("%s rejected. linecount expected %d, got 0", header.ident, header.intnumlines);
  1029. -            if (linecount > header.intnumlines ||
  1030. -                linecount+consec_newlines < header.intnumlines)
  1031. -                log("linecount expected %d, got %d", header.intnumlines, linecount+consec_newlines);
  1032. -        }
  1033. -        /* adjust count for blank lines we stripped off */
  1034. -        if (consec_newlines) {
  1035. -            header.intnumlines -= consec_newlines;
  1036. -            if (header.intnumlines < 0 )
  1037. -                header.intnumlines = 0; /* paranoia */
  1038. -            (void) sprintf(header.numlines, "%d", header.intnumlines);
  1039. -        }
  1040. -
  1041. -    } else {
  1042. -        /* Attach a line count to the article. */
  1043. -        header.intnumlines = linecount;
  1044. -        (void) sprintf(header.numlines, "%d", linecount);
  1045. -    }
  1046. -}
  1047. -
  1048. -/*
  1049. - * Make the directory for a new newsgroup.  ngname should be the
  1050. - * full pathname of the directory.  Do the other stuff too.
  1051. - * The various games with setuid and chown are to try to make sure
  1052. - * the directory is owned by NEWSUSR and NEWSGRP, which is tough to
  1053. - * do if you aren't root.  This will work on a UCB system (which allows
  1054. - * setuid(geteuid()) or a USG system (which allows you to give away files
  1055. - * you own with chown), otherwise you have to change your kernel to allow
  1056. - * one of these things or run with your dirs 777 so that it doesn't matter
  1057. - * who owns them.
  1058. - */
  1059. -mknewsg(fulldir, ngname)
  1060. -char    *fulldir;
  1061. -char    *ngname;
  1062. -{
  1063. -#ifdef USG
  1064. -    register char *p;
  1065. -    char parent[200];
  1066. -    char sysbuf[200];
  1067. -    struct stat sbuf;
  1068. -#endif /* USG */
  1069. -
  1070. -    if (ngname == NULL || !isalpha(ngname[0]))
  1071. -        xerror("Tried to make illegal newsgroup %s", ngname);
  1072. -
  1073. -#ifdef USG
  1074. -    /*
  1075. -     * If the parent is 755 the setuid(getuid)
  1076. -     * will fail, and since mkdir is suid, and our real uid is random,
  1077. -     * the mkdir will fail.  So we have to temporarily chmod it to 777.
  1078. -     */
  1079. -    (void) strcpy(parent, fulldir);
  1080. -    while (p = rindex(parent, '/')) {
  1081. -        *p = '\0';
  1082. -        if (stat(parent, &sbuf) == 0) {
  1083. -            (void) chmod(parent, 0777);
  1084. -            break;
  1085. -        }
  1086. -    }
  1087. -#endif /* USG */
  1088. -
  1089. -    /* Create the directory */
  1090. -    mkparents(fulldir);
  1091. -    if (mkdir(fulldir, 0777) < 0)
  1092. -        xerror("Cannot mkdir %s: %s", fulldir, errmsg(errno));
  1093. -
  1094. -#ifdef USG
  1095. -    (void) chmod(parent, (int)sbuf.st_mode);    /* put it back */
  1096. -    /*
  1097. -     * Give away the directories we just created which were assigned
  1098. -     * our real uid.
  1099. -     */
  1100. -    (void) setuid(uid);
  1101. -    (void) chown(fulldir, duid, dgid);
  1102. -    (void) strcpy(sysbuf, fulldir);
  1103. -    while (p = rindex(sysbuf, '/')) {
  1104. -        *p = '\0';
  1105. -        /* stop when get to last known good parent */
  1106. -        if (strcmp(sysbuf, parent) == 0)
  1107. -            break;
  1108. -        (void) chown(sysbuf, duid, dgid);
  1109. -    }
  1110. -    (void) setuid(duid);
  1111. -#endif /* USG */
  1112. -
  1113. -    log("make newsgroup %s in dir %s", ngname, fulldir);
  1114. -}
  1115. -
  1116. -/*
  1117. - * If any parent directories of this dir don't exist, create them.
  1118. - */
  1119. -mkparents(dname)
  1120. -char *dname;
  1121. -{
  1122. -    char buf[200];
  1123. -    register char *p;
  1124. -
  1125. -    (void) strcpy(buf, dname);
  1126. -    p = rindex(buf, '/');
  1127. -    if (p)
  1128. -        *p = '\0';
  1129. -    if (exists(buf))
  1130. -        return;
  1131. -    mkparents(buf);
  1132. -    if (mkdir(buf, 0777) < 0)
  1133. -        xerror("Can not mkdir %s: %s", buf, errmsg(errno));
  1134. -}
  1135. -
  1136. -cancel()
  1137. -{
  1138. -    register FILE *fp;
  1139. -
  1140. -    log("cancel article %s", filename);
  1141. -    fp = fopen(filename, "r");
  1142. -    if (fp == NULL) {
  1143. -        log("article %s not found", filename);
  1144. -        return;
  1145. -    }
  1146. -    if (hread(&header, fp, TRUE) == NULL)
  1147. -        error("Article is garbled.");
  1148. -    (void) fclose(fp);
  1149. -    (void) unlink(filename);
  1150. -}
  1151. -
  1152. -dounspool()
  1153. -{
  1154. -    register DIR    *dirp;
  1155. -    register struct direct *dir;
  1156. -    register int foundsome;
  1157. -#ifdef VMS
  1158. -    sprintf(bfr, "%s/+rnews", SPOOLDIR);
  1159. -#else /* !VMS */
  1160. -    sprintf(bfr, "%s/.rnews", SPOOLDIR);
  1161. -#endif /* !VMS */
  1162. -
  1163. -    if (chdir(bfr) < 0)
  1164. -        xerror("chdir(%s):%s", bfr, errmsg(errno));
  1165. -
  1166. -    do {
  1167. -        foundsome = 0;
  1168. -        dirp = opendir(".");
  1169. -        if (dirp == NULL)    /* Boy are things screwed up */
  1170. -            xerror("opendir can't open .:%s", errmsg(errno));
  1171. -
  1172. -        while ((dir=readdir(dirp)) != NULL) {
  1173. -            if (dir->d_name[0] == '.')
  1174. -                continue;
  1175. -            sprintf(bfr,"%s -S -p %s", RNEWS, dir->d_name);
  1176. -            system(bfr);
  1177. -            (void) unlink(dir->d_name);
  1178. -            foundsome++;
  1179. -        }
  1180. -        closedir(dirp);
  1181. -    } while (foundsome); /* keep rereading the directory until it's empty */
  1182. -
  1183. -    xxit(0);
  1184. -}
  1185. *-*-END-of-src/inews.c-*-*
  1186. echo x - src/ifuncs.c 1>&2
  1187. sed 's/.//' >src/ifuncs.c <<'*-*-END-of-src/ifuncs.c-*-*'
  1188. -/*
  1189. - * This software is Copyright (c) 1986 by Rick Adams.
  1190. - *
  1191. - * Permission is hereby granted to copy, reproduce, redistribute or
  1192. - * otherwise use this software as long as: there is no monetary
  1193. - * profit gained specifically from the use or reproduction or this
  1194. - * software, it is not sold, rented, traded or otherwise marketed, and
  1195. - * this copyright notice is included prominently in any copy
  1196. - * made.
  1197. - *
  1198. - * The author make no claims as to the fitness or correctness of
  1199. - * this software for any use whatsoever, and it is provided as is. 
  1200. - * Any use of this software is at the user's own risk.
  1201. - *
  1202. - * ifuncs - functions used by inews.
  1203. - */
  1204. -
  1205. -#ifdef SCCSID
  1206. -static char    *SccsId = "@(#)ifuncs.c    2.57    10/29/86";
  1207. -#endif /* SCCSID */
  1208. -
  1209. -#include "iparams.h"
  1210. -#include <errno.h>
  1211. -
  1212. -/*LINTLIBRARY*/
  1213. -
  1214. -#define AFSIZ    4000    /* size of text in the active file for initial malloc */
  1215. -
  1216. -/*
  1217. - * Transmit this article to all interested systems.
  1218. - */
  1219. -
  1220. -#ifdef u370
  1221. -static struct srec srec;
  1222. -#endif /* u370 */
  1223. -
  1224. -static struct hbuf h, hh;
  1225. -
  1226. -#ifdef MULTICAST
  1227. -#define    MAXMCAST    20
  1228. -#define    MAXMCS        10
  1229. -
  1230. -struct multicast {
  1231. -    char mc_name[SBUFLEN];        /* "multi-cast" name */
  1232. -    short mc_syscnt;
  1233. -    char mc_tosys[MAXMCAST][SBUFLEN];
  1234. -} mcast[MAXMCS];
  1235. -
  1236. -static int mccount;
  1237. -#endif /* MULTICAST */
  1238. -
  1239. -#ifndef DBM
  1240. -char *histfile();
  1241. -#endif /* !DBM */
  1242. -
  1243. -#ifdef VMS
  1244. -/*
  1245. - * For VMS/Eunice there are no links: article was moved to firstbufname
  1246. - * before broadcast is reached.  So we read it from there.
  1247. - */
  1248. -extern char firstbufname[];
  1249. -#endif
  1250. -
  1251. -broadcast()
  1252. -{
  1253. -    register char *hptr;
  1254. -    register char *sptr;
  1255. -    register FILE *fp;
  1256. -#ifndef u370
  1257. -    struct srec srec;
  1258. -#endif
  1259. -    char sentbuf[LBUFLEN];
  1260. -    int nsent = 0;
  1261. -    char *sentsys;
  1262. -
  1263. -    /* h is a local copy of the header we can scribble on */
  1264. -#ifdef VMS
  1265. -    fp = xfopen (firstbufname, "r");
  1266. -#else
  1267. -    fp = xfopen(ARTICLE, "r");
  1268. -#endif
  1269. -    if (hread(&h, fp, TRUE) == NULL)
  1270. -        xerror("Cannot reread article");
  1271. -    (void) fclose(fp);
  1272. -
  1273. -    (void) strcpy(sentbuf, h.ident);
  1274. -    (void) strcat(sentbuf, " sent to ");
  1275. -    sentsys = index(sentbuf, 0);
  1276. -    nsent = 0;
  1277. -    /* break path into list of systems. */
  1278. -    sptr = hptr = h.path;
  1279. -    while ((hptr=strpbrk(hptr, NETCHRS)) != NULL) {
  1280. -        *hptr++ = '\0';
  1281. -        sptr = hptr;
  1282. -    }
  1283. -    *sptr = '\0';
  1284. -
  1285. -#ifdef MULTICAST
  1286. -    mccount = 0;
  1287. -#endif /* MULTICAST */
  1288. -
  1289. -    /* loop once per system. */
  1290. -    s_openr();
  1291. -    while (s_read(&srec)) {
  1292. -        char *dist = h.distribution;
  1293. -#ifdef HIDDENNET
  1294. -        if (strncmp(srec.s_name, LOCALSYSNAME, SNLN) == 0)
  1295. -            continue;
  1296. -#endif /* HIDDENNET */
  1297. -        if (strncmp(srec.s_name, FULLSYSNAME, SNLN) == 0)
  1298. -            continue;
  1299. -        if (sptr = srec.s_nosend) {
  1300. -            while (*sptr) {
  1301. -                while (*sptr && *sptr != ',')
  1302. -                    sptr++;
  1303. -                if (*sptr == ',')
  1304. -                    *sptr++ = '\0';
  1305. -            }
  1306. -            *++sptr = '\0';
  1307. -        }
  1308. -        hptr = h.path;
  1309. -        while (*hptr != '\0') {
  1310. -            if (strncmp(srec.s_name, hptr, SNLN) == 0)
  1311. -                goto contin;
  1312. -            if (sptr = srec.s_nosend) {
  1313. -                while (*sptr != '\0') {
  1314. -                    if (strncmp(sptr, hptr, SNLN) == 0)
  1315. -                        goto contin;
  1316. -                    while (*sptr++)
  1317. -                        ;
  1318. -                }
  1319. -            }
  1320. -            while (*hptr++ != '\0')
  1321. -                ;
  1322. -        }
  1323. -        if (!ngmatch(h.nbuf, srec.s_nbuf))
  1324. -            continue;
  1325. -        if (*dist == '\0')
  1326. -            dist = "world";
  1327. -        if (!ngmatch(dist, srec.s_nbuf) && !ngmatch(srec.s_nbuf, dist))
  1328. -                continue;
  1329. -
  1330. -        if (nsent) {
  1331. -            hptr = sentsys;
  1332. -            while ((sptr = index(hptr, ',')) != NULL) {
  1333. -                *sptr = '\0';
  1334. -                if (strcmp(hptr, srec.s_name) == 0) {
  1335. -                    *sptr = ',';
  1336. -                    goto contin;
  1337. -                }
  1338. -                *sptr++ = ',';
  1339. -                for (hptr = sptr; isspace(*hptr); hptr++)
  1340. -                    ;
  1341. -            }
  1342. -            if (strcmp(hptr, srec.s_name) == 0)
  1343. -                continue;
  1344. -        }
  1345. -        /* now we've found a system to send this article to */
  1346. -#ifdef MULTICAST
  1347. -        if (index(srec.s_flags, 'M')) {
  1348. -            /* do a "multi-cast" transmit */
  1349. -            register struct multicast *m;
  1350. -
  1351. -            if (strlen(srec.s_name) >= SBUFLEN ||
  1352. -                strlen(srec.s_xmit) >= SBUFLEN)
  1353. -                xerror("system name too long for multicast");
  1354. -            for (m = mcast; m < &mcast[mccount]; m++)
  1355. -                if (strcmp(srec.s_xmit, m->mc_name) == 0)
  1356. -                    break;
  1357. -            if (m >= &mcast[MAXMCS])
  1358. -                xerror("Too many multicasts");
  1359. -            if (m == &mcast[mccount]) {
  1360. -                mccount++;
  1361. -                m->mc_syscnt = 0;
  1362. -                strcpy(m->mc_name, srec.s_xmit);
  1363. -            }
  1364. -            if (m->mc_syscnt >= MAXMCAST)
  1365. -                xerror("Too many systems for multicast");
  1366. -            strcpy(m->mc_tosys[m->mc_syscnt++], srec.s_name);
  1367. -        } else {
  1368. -            register struct multicast *m;
  1369. -            register char **yptr;
  1370. -            char *sysptrs[MAXMCAST];
  1371. -            int mc;
  1372. -
  1373. -            mc = 0;
  1374. -            for (m = mcast; m < &mcast[mccount]; m++)
  1375. -                if (strcmp(m->mc_name, srec.s_name) == 0) {
  1376. -                    yptr = sysptrs;
  1377. -                    while (mc < m->mc_syscnt)
  1378. -                        *yptr++ = m->mc_tosys[mc++];
  1379. -                    break;
  1380. -                }
  1381. -#ifdef VMS
  1382. -            if (!transmit(&srec, xfopen(firstbufname,"r"), 1,
  1383. -                sysptrs, mc))
  1384. -#else /* !VMS */
  1385. -            if (!transmit(&srec, xfopen(ARTICLE,"r"), 1, sysptrs,
  1386. -                mc))
  1387. -#endif /* !VMS */
  1388. -                continue;
  1389. -        }
  1390. -#else /* !MULTICAST */
  1391. -#ifdef VMS
  1392. -        if (!transmit(&srec, xfopen(firstbufname, "r"),
  1393. -#else /* !VMS */
  1394. -        if (!transmit(&srec, xfopen(ARTICLE, "r"),
  1395. -#endif /* !VMS */
  1396. -            (strncmp(h.nbuf, "to.", 3) != 0),
  1397. -            (char **) NULL, FALSE))
  1398. -                continue;
  1399. -#endif /* !MULTICAST */
  1400. -        if (nsent)
  1401. -            (void) strcat(sentbuf, ", ");
  1402. -        (void) strcat(sentbuf, srec.s_name);
  1403. -        nsent++;
  1404. -    contin:;
  1405. -    }
  1406. -    if (nsent)
  1407. -        log(sentbuf);
  1408. -    s_close();
  1409. -}
  1410. -
  1411. -/*
  1412. - * Transmit file to system.
  1413. - */
  1414. -#define PROC 0004
  1415. -#ifndef MULTICAST
  1416. -/* ARGSUSED */
  1417. -#endif /* !MULTICAST */
  1418. -transmit(sp, ifp, maynotify, sysnames, mc)
  1419. -register struct srec *sp;
  1420. -register FILE *ifp;
  1421. -int maynotify;
  1422. -char **sysnames;
  1423. -int mc;
  1424. -{
  1425. -    register FILE *ofp;
  1426. -    register int c;
  1427. -    register char *ptr;
  1428. -    char TRANS[BUFLEN];
  1429. -    char *argv[20];
  1430. -    register int pid;
  1431. -    extern char firstbufname[];
  1432. -
  1433. -/* A:    afmt: the other machine runs an A news, so we xmit in A format */
  1434. -    int afmt = (index(sp->s_flags, 'A') != NULL);
  1435. -/* B:    use B format (this is the default - don't use this letter elsewise). */
  1436. -/* F:    append name to file */
  1437. -    int appfile = (index(sp->s_flags, 'F') != NULL);
  1438. -/* L:    local: don't send the article unless it was generated locally */
  1439. -    int local = ((ptr = index(sp->s_flags, 'L')) != NULL);
  1440. -/* H:    interpolate history line into command, use existing file */
  1441. -    int history = (index(sp->s_flags, 'H') != NULL);
  1442. -/* m:    moderated: only send if group is moderated */
  1443. -    int sendifmoderated = (index(sp->s_flags, 'm') != NULL);
  1444. -/* u:    unmoderated: only send if group is unmoderated */
  1445. -    int sendifunmoderated = (index(sp->s_flags, 'u') != NULL);
  1446. -/* M:    multi-cast: this is taken care of above, but don't reuse flag */
  1447. -#ifdef MULTICAST
  1448. -/* O:    multi-cast only, don't send article if not multicast hosts */
  1449. -    int multisend = (index(sp->s_flags, 'O') != NULL);
  1450. -#endif /* MULTICAST */
  1451. -/* N:    notify: don't send the article, just tell him we have it */
  1452. -    int notify = maynotify && (index(sp->s_flags, 'N') != NULL);
  1453. -/* S:    noshell: don't fork a shell to execute the xmit command */
  1454. -    int noshell = (index(sp->s_flags, 'S') != NULL);
  1455. -/* U:    useexist: use the -c option to uux to use the existing copy */
  1456. -    int useexist = (index(sp->s_flags, 'U') != NULL);
  1457. -/* I:    append messageid to file. implies F flag */
  1458. -    int appmsgid = maynotify && (index(sp->s_flags, 'I') != NULL);
  1459. -
  1460. -    if (notify)
  1461. -        appfile = appmsgid = FALSE;
  1462. -
  1463. -    if (!appfile)
  1464. -        appfile = appmsgid;
  1465. -
  1466. -    if (local && mode == PROC) {
  1467. -        local = 0;
  1468. -        while (isdigit(*++ptr))
  1469. -            local = local * 10 + *ptr - '0';
  1470. -        for (ptr = h.path; *ptr != '\0' && local >= 0; local--)
  1471. -            while (*ptr++ != '\0')
  1472. -                ;
  1473. -        if (local < 0) {
  1474. -            (void) fclose(ifp);
  1475. -            return FALSE;
  1476. -        }
  1477. -    }
  1478. -
  1479. -    /*
  1480. -    ** Do not transmit to system specified in -x flag.
  1481. -    */
  1482. -    if (not_here[0] && strcmp(not_here, sp->s_name) == 0) {
  1483. -        (void) fclose(ifp);
  1484. -        return FALSE;
  1485. -    }
  1486. -
  1487. -#ifdef DEBUG
  1488. -    printf("Transmitting to '%s'\n", sp->s_name);
  1489. -#endif /* DEBUG */
  1490. -
  1491. -#ifdef MULTICAST
  1492. -    if (multisend && mc == 0) {
  1493. -        (void) fclose(ifp);
  1494. -        return FALSE;
  1495. -    }
  1496. -#endif /* MULTICAST */
  1497. -
  1498. -    if ((sendifmoderated && is_mod[0] == '\0') ||
  1499. -        (sendifunmoderated && is_mod[0] != '\0')) {
  1500. -        fclose(ifp);
  1501. -        return FALSE;
  1502. -    }
  1503. -
  1504. -    if (appmsgid || (!appfile && !useexist && !history)) {
  1505. -        if (!hread(&hh, ifp, TRUE)) {
  1506. -            logerr("Bad header, not transmitting %s re %s to %s",
  1507. -                hh.ident, hh.title, sp->s_name);
  1508. -            (void) fclose(ifp);
  1509. -            return FALSE;
  1510. -        }
  1511. -        if (hh.nbuf[0] == '\0') {
  1512. -            fprintf(stderr, "Article not subscribed to by %s\n", sp->s_name);
  1513. -            (void) fclose(ifp);
  1514. -            return FALSE;
  1515. -        }
  1516. -        (void) sprintf(TRANS, "%s/trXXXXXX", SPOOL);
  1517. -    }
  1518. -
  1519. -    if (notify) {
  1520. -        char oldid[50];
  1521. -        (void) sprintf(hh.title, "ihave %s %s", hh.ident, FULLSYSNAME);
  1522. -        (void) strcpy(hh.ctlmsg, hh.title);
  1523. -        (void) strcpy(hh.numlines, "0");
  1524. -        (void) sprintf(hh.nbuf, "to.%s.ctl", sp->s_name);
  1525. -        (void) strcpy(oldid, hh.ident);
  1526. -        getident(&hh);
  1527. -        log("tell %s about %s, notif. id %s",
  1528. -            sp->s_name, oldid, hh.ident);
  1529. -    }
  1530. -
  1531. -    if (appfile) {
  1532. -        if (firstbufname[0] == '\0') {
  1533. -            extern char histline[];
  1534. -            localize("junk");
  1535. -            savehist(histline);
  1536. -            xerror("No file name to xmit from");
  1537. -        }
  1538. -        if (sp->s_xmit[0] == '\0')
  1539. -            sprintf(sp->s_xmit, "%s/%s%s", BATCHDIR, sp->s_name,
  1540. -                appmsgid ? ".ihave" : "");
  1541. -#ifdef IHCC
  1542. -        (void) sprintf(TRANS, "%s/%s/%s", logdir(HOME), BATCHDIR, sp->s_xmit);
  1543. -        ofp = fopen(TRANS, "a");
  1544. -#else /* !IHCC */
  1545. -        ofp = fopen(sp->s_xmit, "a");
  1546. -#endif /* !IHCC */
  1547. -        if (ofp == NULL)
  1548. -            xerror("Cannot append to %s", sp->s_xmit);
  1549. -        fprintf(ofp, "%s", appmsgid ? hh.ident : firstbufname);
  1550. -#ifdef MULTICAST
  1551. -        while (--mc >= 0)
  1552. -            fprintf(ofp, " %s", *sysnames++);
  1553. -#endif /* !MULTICAST */
  1554. -        putc('\n', ofp);
  1555. -        (void) fclose(ofp);
  1556. -        (void) fclose(ifp);
  1557. -        return TRUE;
  1558. -    }
  1559. -    else if (useexist) {
  1560. -        if (firstbufname[0] == '\0')
  1561. -            xerror("No file name to xmit from");
  1562. -        if (*sp->s_xmit == '\0')
  1563. -#ifdef UXMIT
  1564. -            (void) sprintf(bfr, UXMIT, sp->s_name, firstbufname);
  1565. -#else
  1566. -            xerror("UXMIT not defined for U flag");
  1567. -#endif
  1568. -        else
  1569. -#ifdef MULTICAST
  1570. -            makeargs(bfr, sp->s_xmit, firstbufname, sysnames, mc);
  1571. -#else
  1572. -            (void) sprintf(bfr, sp->s_xmit, firstbufname);
  1573. -#endif
  1574. -        (void) fclose(ifp);
  1575. -    } else if (history) {
  1576. -        extern char histline[];
  1577. -
  1578. -        if (*sp->s_xmit == '\0')
  1579. -            xerror("no xmit command with H flag");
  1580. -#ifdef MULTICAST
  1581. -        makeargs(bfr, sp->s_xmit, histline, sysnames, mc);
  1582. -#else
  1583. -        (void) sprintf(bfr, sp->s_xmit, histline);
  1584. -#endif
  1585. -    } else {
  1586. -        ofp = xfopen(mktemp(TRANS), "w");
  1587. -        if (afmt) {
  1588. -#ifdef OLD
  1589. -            fprintf(ofp, "A%s\n%s\n%s!%s\n%s\n%s\n", oident(hh.ident), hh.nbuf, FULLSYSNAME,
  1590. -                hh.path, hh.subdate, hh.title);
  1591. -#else /* !OLD */
  1592. -            logerr("Must have OLD defined to use A flag for xmit");
  1593. -            return FALSE;
  1594. -#endif /* !OLD */
  1595. -        } else
  1596. -            hwrite(&hh, ofp);
  1597. -        if (!notify)
  1598. -            while ((c = getc(ifp)) != EOF)
  1599. -                putc(c, ofp);
  1600. -        if (ferror(ofp))
  1601. -            xerror("write failed on transmit");
  1602. -        (void) fclose(ifp);
  1603. -        (void) fclose(ofp);
  1604. -        if (*sp->s_xmit == '\0')
  1605. -            (void) sprintf(bfr, DFTXMIT, sp->s_name, TRANS);
  1606. -        else
  1607. -#ifdef MULTICAST
  1608. -            makeargs(bfr, sp->s_xmit, TRANS, sysnames, mc);
  1609. -#else /* !MULTICAST */
  1610. -            (void) sprintf(bfr, sp->s_xmit, TRANS);
  1611. -#endif /* !MULTICAST */
  1612. -    }
  1613. -
  1614. -    /* At this point, the command to be executed is in bfr. */
  1615. -    if (noshell) {
  1616. -        if (pid = vfork())
  1617. -            fwait(pid);
  1618. -        else {
  1619. -            (void) close(0);
  1620. -            (void) open(TRANS, 0);
  1621. -            ptr = bfr;
  1622. -            for (pid = 0; pid < 19; pid++) {
  1623. -                while (isspace(*ptr))
  1624. -                    *ptr++ = 0;
  1625. -                argv[pid] = ptr;
  1626. -                while (!isspace(*++ptr) && *ptr)
  1627. -                    ;
  1628. -                if (!*ptr)
  1629. -                    break;
  1630. -            }
  1631. -            argv[++pid] = 0;
  1632. -            (void) setgid(gid);
  1633. -            (void) setuid(uid);
  1634. -            execv(argv[0], argv);
  1635. -            xerror("Can't execv %s", argv[0]);
  1636. -        }
  1637. -    } else {
  1638. -        if (!history && sp->s_xmit[0] && !index(bfr, '<')) {
  1639. -            char newcmd[LBUFLEN];
  1640. -
  1641. -            (void) sprintf(newcmd, "(%s) <%s", bfr,
  1642. -                useexist ? firstbufname : TRANS);
  1643. -            system(newcmd);
  1644. -        } else
  1645. -            system(bfr);
  1646. -    }
  1647. -    if (!appfile && !useexist && !history)
  1648. -        (void) unlink(TRANS);
  1649. -    (void) fclose(ifp);
  1650. -    return TRUE;
  1651. -}
  1652. -
  1653. -#ifdef MULTICAST
  1654. -makeargs(buf, cmd, arg2, sysargs, sac)
  1655. -char *buf;
  1656. -char *cmd;
  1657. -char *arg2;
  1658. -register char **sysargs;
  1659. -int sac;
  1660. -{
  1661. -    register char *p = cmd;
  1662. -    register char *q;
  1663. -    register ac = 0;
  1664. -    register char *b = buf;
  1665. -
  1666. -    q = p;
  1667. -    do {
  1668. -        if (q = index(q, ' '))
  1669. -            *q = '\0';
  1670. -        if (index(p, '%')) {
  1671. -            switch (++ac) {
  1672. -            case 1:
  1673. -                while (--sac >= 0) {
  1674. -                    sprintf(b, p, *sysargs++);
  1675. -                    b = index(b, '\0');
  1676. -                }
  1677. -                break;
  1678. -            case 2:
  1679. -                sprintf(b, p, arg2);
  1680. -                b = index(b, '\0');
  1681. -                break;
  1682. -            default:
  1683. -                if (q)
  1684. -                    *q = ' ';
  1685. -                xerror("badly formed command: %s", cmd);
  1686. -            }
  1687. -        } else {
  1688. -            strcpy(b, p);
  1689. -            b = index(b, '\0');
  1690. -        }
  1691. -        if (q) {
  1692. -            *q = ' ';
  1693. -            p = q;
  1694. -            while (isspace(*q))
  1695. -                q++;
  1696. -        }
  1697. -    } while (q != NULL);
  1698. -}
  1699. -#endif /* MULTICAST */
  1700. -
  1701. -typedef struct {
  1702. -    char *dptr;
  1703. -    int dsize;
  1704. -} datum;
  1705. -
  1706. -/*
  1707. - * Return TRUE if we have seen this file before, else FALSE.
  1708. - */
  1709. -history(hp)
  1710. -struct hbuf *hp;
  1711. -{
  1712. -#ifdef DBM
  1713. -    datum lhs, rhs;
  1714. -    datum fetch();
  1715. -#else /* !DBM */
  1716. -    register FILE *hfp;
  1717. -    register char *p;
  1718. -#endif /* !DBM */
  1719. -    char lcident[BUFLEN];
  1720. -    extern char histline[];
  1721. -
  1722. -#ifdef DEBUG
  1723. -    fprintf(stderr,"history(%s)\n", hp->ident);
  1724. -#endif /* DEBUG */
  1725. -    /*
  1726. -     * Make the article ID case insensitive.
  1727. -     */
  1728. -    (void) strcpy(lcident, hp->ident);
  1729. -    lcase(lcident);
  1730. -
  1731. -    idlock(lcident);
  1732. -#ifdef DBM
  1733. -    initdbm(ARTFILE);
  1734. -    lhs.dptr = lcident;
  1735. -    lhs.dsize = strlen(lhs.dptr) + 1;
  1736. -    rhs = fetch(lhs);
  1737. -    if (rhs.dptr)
  1738. -        return(TRUE);
  1739. -#else /* !DBM */
  1740. -    hfp = xfopen(histfile(lcident), "r");
  1741. -    while (fgets(bfr, BUFLEN, hfp) != NULL) {
  1742. -        p = index(bfr, '\t');
  1743. -        if (p == NULL)
  1744. -            p = index(bfr, '\n');
  1745. -        if (p != NULL)    /* can happen if nulls in file */
  1746. -            *p = 0;
  1747. -        lcase(bfr);
  1748. -
  1749. -        if (strcmp(bfr, lcident) == 0) {
  1750. -            (void) fclose(hfp);
  1751. -            idunlock();
  1752. -#ifdef DEBUG
  1753. -            fprintf(stderr,"history returns true\n");
  1754. -#endif /* DEBUG */
  1755. -            return TRUE;
  1756. -        }
  1757. -    }
  1758. -    (void) fclose(hfp);
  1759. -#endif /* !DBM */
  1760. -    histline[0] = '\0';
  1761. -    addhist(hp->ident);
  1762. -    addhist("\t");
  1763. -#ifdef DEBUG
  1764. -    fprintf(stderr,"history returns false\n");
  1765. -#endif
  1766. -    return FALSE;
  1767. -}
  1768. -
  1769. -char histline[PATHLEN];
  1770. -
  1771. -addhist(msg)
  1772. -char *msg;
  1773. -{
  1774. -    (void) strcat(histline, msg);
  1775. -}
  1776. -
  1777. -savehist(hline)
  1778. -char *hline;
  1779. -{
  1780. -    register FILE *hfp;
  1781. -    datum lhs, rhs;
  1782. -    long fpos;
  1783. -    register char *p;
  1784. -
  1785. -    hfp = xfopen(ARTFILE, "a");
  1786. -    (void) fseek(hfp, 0L, 2); /* Unisoft 5.1 doesn't seek to EOF on 'a' */
  1787. -    fpos = ftell(hfp);
  1788. -    fprintf(hfp, "%s\n", hline);
  1789. -    (void) fclose(hfp);
  1790. -#ifdef DBM
  1791. -    /* We assume that history has already been called, calling dbminit. */
  1792. -    p = index(hline, '\t');
  1793. -    if (p)
  1794. -        *p = 0;
  1795. -    lcase(hline);
  1796. -    lhs.dptr = hline;
  1797. -    lhs.dsize = strlen(lhs.dptr) + 1;
  1798. -    rhs.dptr = (char *)&fpos;
  1799. -    rhs.dsize = sizeof fpos;
  1800. -    store(lhs, rhs);
  1801. -#else /* !DBM */
  1802. -    /* also append to proper history subfile */
  1803. -    hfp = xfopen(histfile(hline), "a");
  1804. -    fprintf(hfp, "%s\n", hline);
  1805. -    (void) fclose(hfp);
  1806. -#endif /* !DBM */
  1807. -    idunlock();
  1808. -}
  1809. -
  1810. -/*
  1811. - * Save partial news.
  1812. - */
  1813. -/* ARGSUSED */
  1814. -newssave(fd, dummy)
  1815. -FILE *fd;
  1816. -char *dummy;
  1817. -{
  1818. -    register FILE *tofd, *fromfd;
  1819. -    char sfname[BUFLEN];
  1820. -    register int c;
  1821. -    time_t tim;
  1822. -
  1823. -    if (fd == NULL)
  1824. -        fromfd = xfopen(INFILE, "r");
  1825. -    else
  1826. -        fromfd = fd;
  1827. -    (void) umask(savmask);
  1828. -    (void) setgid(gid);
  1829. -    (void) setuid(uid);
  1830. -
  1831. -    (void) sprintf(sfname, "%s/%s", userhome, PARTIAL);
  1832. -    if ((tofd = fopen(sfname, "a")) == NULL)
  1833. -        xerror("Cannot save partial news in %s", sfname);
  1834. -    (void) time(&tim);
  1835. -    fprintf(tofd, "----- News saved at %s\n", arpadate(&tim));
  1836. -    while ((c = getc(fromfd)) != EOF)
  1837. -        putc(c, tofd);
  1838. -    (void) fclose(fromfd);
  1839. -    (void) fclose(tofd);
  1840. -    printf("News saved in %s\n", sfname);
  1841. -    xxit(1);
  1842. -}
  1843. -
  1844. -/*
  1845. - * Handle dates in header.
  1846. - */
  1847. -
  1848. -dates(hp)
  1849. -struct hbuf *hp;
  1850. -{
  1851. -    time_t edt;
  1852. -
  1853. -    if (*hp->subdate) {
  1854. -        if (cgtdate(hp->subdate) < 0) {
  1855. -            error("Cannot parse submittal date '%s'", hp->subdate);
  1856. -        }
  1857. -    } else {
  1858. -        (void) time(&edt);
  1859. -        (void) strcpy(hp->subdate, arpadate(&edt));
  1860. -    }
  1861. -}
  1862. -
  1863. -#define LOCKSIZE    128
  1864. -char lockname[LOCKSIZE];
  1865. -
  1866. -idlock(str)
  1867. -char *str;
  1868. -{
  1869. -    register int i;
  1870. -    register char *cp, *scp;
  1871. -    char tempname[LOCKSIZE];
  1872. -    time_t now;
  1873. -    struct stat sbuf;
  1874. -    extern int errno;
  1875. -#ifdef    VMS
  1876. -    int fd;
  1877. -
  1878. -    (void) sprintf(lockname, "/tmp/%s.l.1", str);
  1879. -    while ((fd = creat(lockname, 0444)) < 0) {
  1880. -#else /* !VMS */
  1881. -    (void) strcpy(tempname, "/tmp/LTMP.XXXXXX");
  1882. -    (void) mktemp(tempname);
  1883. -    (void) strcpy(lockname, "/tmp/L");
  1884. -    i = strlen(lockname);
  1885. -    cp = &lockname[i];
  1886. -    scp = str - 1;
  1887. -    while (i++ < LOCKSIZE && *++scp != '\0')
  1888. -        if (*scp == '/')    /* slash screws up the open */
  1889. -            *cp++ = '.';
  1890. -        else
  1891. -            *cp++ = *scp;
  1892. -    *cp = '\0';
  1893. -#ifdef FOURTEENMAX
  1894. -    lockname[5 /* /tmp/ */ + 14] = '\0';
  1895. -#endif
  1896. -    i = creat(tempname, 0666);
  1897. -    if (i < 0)
  1898. -        xerror("Cannot creat %s: errno %d", tempname, errno);
  1899. -    (void) close(i);
  1900. -    while (link(tempname, lockname)) {
  1901. -#endif /* !VMS */
  1902. -        (void) time(&now);
  1903. -        if (stat(lockname, &sbuf) < 0)
  1904. -            xerror("Directory permission problem in /tmp");
  1905. -
  1906. -        if (sbuf.st_mtime + 10*60 < now) {
  1907. -            (void) unlink(lockname);
  1908. -            logerr("Article %s locked up", str);
  1909. -            break;
  1910. -        }
  1911. -        log("waiting on lock for %s", lockname);
  1912. -        sleep((unsigned)60);
  1913. -    }
  1914. -#ifdef VMS
  1915. -    (void) close(fd);
  1916. -#endif
  1917. -    (void) unlink(tempname);
  1918. -}
  1919. -
  1920. -idunlock()
  1921. -{
  1922. -    (void) unlink(lockname);
  1923. -}
  1924. -
  1925. -/*
  1926. - * Put a unique name into header.ident.
  1927. - */
  1928. -getident(hp)
  1929. -struct hbuf *hp;
  1930. -{
  1931. -    long seqn;
  1932. -    register FILE *fp;
  1933. -
  1934. -    lock();
  1935. -    fp = xfopen(SEQFILE, "r");
  1936. -    (void) fgets(bfr, BUFLEN, fp);
  1937. -    (void) fclose(fp);
  1938. -    seqn = atol(bfr) + 1;
  1939. -/*
  1940. - * For Eunice, this breaks if SEQFILE is not in Unix format.
  1941. - */
  1942. -    fp = xfopen(SEQFILE, "r+w");
  1943. -    fprintf(fp, "%ld\n", seqn);
  1944. -    (void) fclose(fp);
  1945. -    unlock();
  1946. -#ifdef HIDDENNET
  1947. -    if (strcmp(LOCALSYSNAME, FULLSYSNAME))
  1948. -        (void) sprintf(hp->ident, "<%ld@%s.%s%s>", seqn, LOCALSYSNAME, FULLSYSNAME,
  1949. -        MYDOMAIN);
  1950. -    else
  1951. -#endif /* !HIDDENNET */
  1952. -    (void) sprintf(hp->ident, "<%ld@%s%s>", seqn, FULLSYSNAME, MYDOMAIN);
  1953. -}
  1954. -
  1955. -/*
  1956. - * Check that header.nbuf contains only valid newsgroup names;
  1957. - * exit with error if not valid.
  1958. - */
  1959. -ngfcheck(isproc)
  1960. -{
  1961. -    register FILE *    f;
  1962. -    register char *    cp;
  1963. -    register int    i, j;
  1964. -    register int    ngcount, okcount, havealiased;
  1965. -    register int    pass;
  1966. -    char *        ngs[sizeof header.nbuf / 2];
  1967. -    char        uses[sizeof header.nbuf / 2];
  1968. -    char        tbuf[sizeof header.nbuf];
  1969. -    char        abuf[BUFLEN];
  1970. -
  1971. -    havealiased = ngcount = 0;
  1972. -    is_mod[0] = '\0';
  1973. -    /*
  1974. -    ** Split header.nbuf into constituent newsgroups.
  1975. -    ** Zap "local" newsgroups of articles from remote sites.
  1976. -    */
  1977. -    cp = tbuf;
  1978. -    (void) strcpy(cp, header.nbuf);
  1979. -    for ( ; ; ) {
  1980. -        while (*cp == NGDELIM || *cp == ' ')
  1981. -            ++cp;
  1982. -        if (*cp == '\0')
  1983. -            break;
  1984. -        ngs[ngcount] = cp;
  1985. -        do {
  1986. -            ++cp;
  1987. -        } while (*cp != '\0' && *cp != NGDELIM && *cp != ' ');
  1988. -        if (*cp != '\0')
  1989. -            *cp++ = '\0';
  1990. -        /*
  1991. -        ** Check for local only distribution on incoming
  1992. -        ** newsgroups.  This might occur if someone posted to
  1993. -        ** general,net.unix
  1994. -        */
  1995. -        if (isproc && index(ngs[ngcount], '.') == NULL &&
  1996. -            index(header.nbuf, '.') != NULL) {
  1997. -                logerr("Local group '%s' removed",
  1998. -                    ngs[ngcount]);
  1999. -                continue;
  2000. -        }
  2001. -        uses[ngcount] = 1;    /* it should go in "Newsgroups" line */
  2002. -        ++ngcount;
  2003. -    }
  2004. -    /*
  2005. -    ** Check groups against active file.
  2006. -    */
  2007. -recheck:
  2008. -    okcount = 0;
  2009. -    rewind(actfp); clearerr(actfp);
  2010. -    while (okcount < ngcount && fgets(bfr, BUFLEN, actfp) == bfr) {
  2011. -        if ((cp = index(bfr, ' ')) == NULL)
  2012. -            continue;    /* strange line in input! */
  2013. -        /* newsgroup 12345 12345 X */
  2014. -        /*  cp +    01234567890123 */
  2015. -        if (!isproc && cp[13]  == 'n')
  2016. -            continue;    /* can't post to this group! */
  2017. -        *cp = '\0';
  2018. -        for (i = 0; i < ngcount; ++i)
  2019. -            if (uses[i] >= 1 && strcmp(bfr, ngs[i]) == 0) {
  2020. -                uses[i] = 2;    /* it should be localized too */
  2021. -                if (cp[13] == 'm')
  2022. -                    strcpy(is_mod, bfr);
  2023. -                ++okcount;
  2024. -            }
  2025. -    }
  2026. -#ifdef ALWAYSALIAS
  2027. -    okcount = 0;
  2028. -#endif /* ALWAYSALIAS */
  2029. -    /*
  2030. -    ** Handle groups absent from active file.
  2031. -    */
  2032. -    if (havealiased == 0 && okcount < ngcount) {
  2033. -        /*
  2034. -        ** See if remaining groups are in our alias list.
  2035. -        */
  2036. -        f = xfopen(ALIASES, "r");
  2037. -        while (okcount < ngcount && fscanf(f, "%s %s", abuf, bfr) == 2)
  2038. -            for (i = 0; i < ngcount; ++i) {
  2039. -#ifndef ALWAYSALIAS
  2040. -                if (uses[i] == 2)
  2041. -                    continue;
  2042. -#endif /* ALWAYSALIAS */
  2043. -                if (strcmp(ngs[i], abuf) != 0)
  2044. -                    continue;
  2045. -                if (isproc)
  2046. -                    cp = "Aliased newsgroup %s to %s";
  2047. -                else
  2048. -                    cp = "Please change %s to %s";
  2049. -                logerr(cp, abuf, bfr);
  2050. -                ngs[i] = AllocCpy(bfr);
  2051. -                uses[i] = 2;
  2052. -                ++havealiased;
  2053. -                ++okcount;
  2054. -            }
  2055. -        (void) fclose(f);
  2056. -        for (i = 0; i < ngcount; ++i) {
  2057. -            if (uses[i] == 2)
  2058. -                continue;
  2059. -            if (isproc)
  2060. -                cp = "Unknown newsgroup '%s' not localized";
  2061. -            else
  2062. -                cp = "Unknown newsgroup '%s'";
  2063. -            logerr(cp, ngs[i]);
  2064. -#ifdef ALWAYSALIAS
  2065. -            ++okcount;    /* so we know to exit below */
  2066. -        }
  2067. -        if (!isproc && okcount > 0)
  2068. -#else /* !ALWAYSALIAS */
  2069. -        }
  2070. -        if (!isproc)
  2071. -#endif /* !ALWAYSALIAS */
  2072. -            newssave(infp, (char *) NULL);
  2073. -        /*
  2074. -         * Unfortunately, if you alias an unmoderated group to a
  2075. -         * moderated group, you must recheck the active file to see
  2076. -         * if the new group is moderated. Rude but necessary.
  2077. -         */
  2078. -        if (havealiased)
  2079. -            goto recheck;    
  2080. -    }
  2081. -    /*
  2082. -    ** Zap duplicates.
  2083. -    */
  2084. -    for (i = 0; i < ngcount - 1; ++i) {
  2085. -        if (uses[i] == 0)
  2086. -            continue;
  2087. -        for (j = i + 1; j < ngcount; ++j) {
  2088. -            if (uses[j] == 0)
  2089. -                continue;
  2090. -            if (strcmp(ngs[i], ngs[j]) != 0)
  2091. -                continue;
  2092. -            logerr("Duplicate '%s' removed", ngs[j]);
  2093. -            if (uses[i] < uses[j])
  2094. -                uses[i] = uses[j];
  2095. -            uses[j] = 0;
  2096. -        }
  2097. -    }
  2098. -    for (pass = 1; pass <= 2; ++pass) {
  2099. -        register int    avail;
  2100. -
  2101. -        if (pass == 1) {
  2102. -            /*
  2103. -            ** Rewrite header.nbuf.
  2104. -            */
  2105. -            cp = header.nbuf;
  2106. -            avail = sizeof header.nbuf;
  2107. -        } else {
  2108. -            /*
  2109. -            ** Fill in nbuf.
  2110. -            */
  2111. -            cp = nbuf;
  2112. -            avail = sizeof nbuf;
  2113. -        }
  2114. -        for (i = 0; i < ngcount; ++i) {
  2115. -            if (uses[i] < pass)
  2116. -                continue;
  2117. -            j = strlen(ngs[i]);
  2118. -            if (j + 2 > avail) {
  2119. -                logerr("Redone Newsgroups too long");
  2120. -                break;
  2121. -            }
  2122. -            (void) strcpy(cp, ngs[i]);
  2123. -            cp += j;
  2124. -            *cp++ = (pass == 1) ? NGDELIM : '\0';
  2125. -            avail -= (j + 1);
  2126. -        }
  2127. -        if (pass == 1) {
  2128. -            if (cp == header.nbuf)
  2129. -                *cp = '\0';
  2130. -            else    *(cp - 1) = '\0';
  2131. -        } else    *cp = '\0';
  2132. -    }
  2133. -    /*
  2134. -    ** Free aliases.
  2135. -    */
  2136. -    for (i = 0; i < ngcount; ++i)
  2137. -        if (ngs[i] < tbuf || ngs[i] > &tbuf[sizeof tbuf - 1])
  2138. -            free(ngs[i]);
  2139. -    return nbuf[0] == '\0';
  2140. -}
  2141. -
  2142. -/*
  2143. - * Figure out who posted the article (which is locally entered).
  2144. - * The results are placed in the header structure hp.
  2145. - */
  2146. -gensender(hp, logname)
  2147. -struct hbuf *hp;
  2148. -char *logname;
  2149. -{
  2150. -    register char *fn, *p;
  2151. -    char buf[BUFLEN];
  2152. -    char *fullname(), *getenv();
  2153. -    int fd, n;
  2154. -
  2155. -    if ((fn = getenv("NAME")) == NULL) {
  2156. -        (void) sprintf(buf, "%s/%s", userhome, ".name");
  2157. -        if ((fd = open(buf, 0)) >= 0) {
  2158. -            n = read(fd, buf, sizeof buf);
  2159. -            (void) close(fd);
  2160. -            if (n > 0 && buf[0] >= 'A') {
  2161. -                for (p = fn = buf; *p; p++)
  2162. -                    if (*p < ' ')
  2163. -                        *p = '\0';
  2164. -            }
  2165. -        }
  2166. -    }
  2167. -
  2168. -    if (fn == NULL)
  2169. -        fn = fullname(logname);
  2170. -
  2171. -    (void) sprintf(hp->path, "%s", logname);
  2172. -    (void) sprintf(hp->from, "%s@%s%s (%s)", logname, FULLSYSNAME, MYDOMAIN, fn);
  2173. -}
  2174. -
  2175. -/*
  2176. - * Trap interrupts.
  2177. - */
  2178. -onsig(n)
  2179. -int n;
  2180. -{
  2181. -    static int numsigs = 0;
  2182. -    /*
  2183. -     * Most UNIX systems reset caught signals to SIG_DFL.
  2184. -     * This bad design requires that the trap be set again here.
  2185. -     * Unfortunately, if the signal recurs before the trap is set,
  2186. -     * the program will die, possibly leaving the lock in place.
  2187. -     */
  2188. -    if (++numsigs > 100) {
  2189. -        logerr("inews ran away looping on signal %d", n);
  2190. -        xxit(1);
  2191. -    }
  2192. -    (void) signal(n, onsig);
  2193. -    SigTrap = n;
  2194. -}
  2195. -
  2196. -#ifdef BATCH
  2197. -/*
  2198. - * If the stdin begins with "#", we assume we have been fed a batched
  2199. - * shell script which looks like this:
  2200. - *    #! rnews 1234
  2201. - *    article with 1234 chars
  2202. - *    #! rnews 4321
  2203. - *    article with 4321 chars
  2204. - *
  2205. - * In this case we just exec the unbatcher and let it unpack and call us back.
  2206. - *
  2207. - * Note that there is a potential security hole here.  If the batcher is
  2208. - * /bin/sh, someone could ship you arbitrary stuff to run as shell commands.
  2209. - * The main protection you have is that the effective uid will be news, not
  2210. - * uucp and not the super user.  (That, plus the fact that BATCH is set to
  2211. - * "unbatch" as the system is distributed.)  If you want to run a batched link
  2212. - * and you are security conscious, do not use /bin/sh as the unbatcher.
  2213. - * the thing to do is to change BATCH in your localize.sh file from /bin/sh
  2214. - * to some restricted shell which can only run rnews.
  2215. - */
  2216. -checkbatch()
  2217. -{
  2218. -    int c;
  2219. -
  2220. -    c = getc(infp);
  2221. -    if (c != EOF)
  2222. -        (void) ungetc(c, infp);
  2223. -    clearerr(infp);
  2224. -    if (c == '#') {
  2225. -        char cmd[BUFLEN], unbatcher[BUFLEN], arg1[BUFLEN], arg2[BUFLEN];
  2226. -        register char *cp;
  2227. -        int n;
  2228. -
  2229. -        reset_infp();
  2230. -        /*
  2231. -         * For efficiency, try and recognize the most common
  2232. -         * forms of batching and exec them directly
  2233. -         */
  2234. -        n = read(0, cmd, BUFLEN-1);
  2235. -        if (n <= 0)    /* Can't happen */
  2236. -            xerror("can't read stdin to unbatch");
  2237. -        cmd[n] = '\0';
  2238. -        cp = index(cmd, '\n');
  2239. -        if (cp)
  2240. -            *cp = '\0';
  2241. -        /* now put stdin at the "right" place for the exec */
  2242. -        (void) lseek(0,1L+(long)(cp - cmd), 0);
  2243. -        if( strncmp(cmd, "#! cunbatch", 11) == 0) {
  2244. -            (void) strcpy(unbatcher, "/bin/sh");
  2245. -            (void) strcpy(arg1, "-c");
  2246. -            (void) sprintf(arg2, "%s/compress -d | %s/%s",
  2247. -                LIB, LIB, BATCH);
  2248. -        } else if (strncmp(cmd, "#! c7unbatch", 12) == 0) {
  2249. -            (void) strcpy(unbatcher, "/bin/sh");
  2250. -            (void) strcpy(arg1, "-c");
  2251. -            (void) sprintf(arg2,
  2252. -                "%s/decode | %s/compress -d | %s/%s",
  2253. -                LIB, LIB, LIB, BATCH);
  2254. -        } else {
  2255. -            (void) lseek(0, 0L, 0);
  2256. -            (void) sprintf(unbatcher, "%s/%s", LIB, BATCH);
  2257. -            arg1[0] = '\0';
  2258. -            arg2[0] = '\0';
  2259. -        }
  2260. -        execl(unbatcher, "news-unpack", arg1, arg2, (char *)0);
  2261. -        xerror("Unable to exec %s to unpack news.", unbatcher);
  2262. -    }
  2263. -}
  2264. -
  2265. -/*
  2266. - * We've already done a read on stdin, and we want to seek back to the
  2267. - * beginning.  We want the real file descriptor (beyond buffers) to
  2268. - * reflect the true beginning.  Do whatever is necessary.
  2269. - */
  2270. -reset_infp()
  2271. -{
  2272. -    register FILE *ofd;
  2273. -    register int c;
  2274. -    char *ofdname;
  2275. -    long lseek();
  2276. -
  2277. -    /* First try to seek back - if so, it's a cheap way back. */
  2278. -    if (lseek(0, 0L, 0) == 0L)
  2279. -        return;
  2280. -
  2281. -    /* Can't seek, so have to copy input to a file and use that. */
  2282. -    ofdname = "/tmp/inewsXXXXXX";
  2283. -    (void) mktemp(ofdname);
  2284. -    ofd = fopen(ofdname, "w");
  2285. -    while ((c=getc(infp)) != EOF)
  2286. -        putc(c, ofd);
  2287. -    if (ferror(ofd))
  2288. -        xerror("write failed on temp file %s", ofdname);
  2289. -    (void) fclose(ofd);
  2290. -    (void) fclose(infp);
  2291. -
  2292. -    /* Now for a few lower level hacks to reopen stdin and make
  2293. -     * absolutely sure that the right fd's are done for the exec.
  2294. -     */
  2295. -    (void) close(0);        /* make sure stdin is really closed. */
  2296. -    (void) open(ofdname, 0);
  2297. -    (void) unlink(ofdname);        /* to avoid cleaning it up later. */
  2298. -}
  2299. -#endif /* BATCH */
  2300. -
  2301. -/*
  2302. - *    Exit and cleanup.
  2303. - */
  2304. -xxit(status)
  2305. -int status;
  2306. -{
  2307. -    (void) unlink(INFILE);
  2308. -    (void) unlink(ARTICLE);
  2309. -    while (lockcount > 0)
  2310. -        unlock();
  2311. -    idunlock();
  2312. -    exit(status);
  2313. -}
  2314. -
  2315. -rwaccess(fname)
  2316. -char *fname;
  2317. -{
  2318. -    int fd;
  2319. -
  2320. -    fd = open(fname, 2);
  2321. -    if (fd < 0)
  2322. -        return 0;
  2323. -    (void) close(fd);
  2324. -    return 1;
  2325. -}
  2326. -
  2327. -exists(fname)
  2328. -char *fname;
  2329. -{
  2330. -    int fd;
  2331. -
  2332. -    fd = open(fname, 0);
  2333. -    if (fd < 0)
  2334. -        return 0;
  2335. -    (void) close(fd);
  2336. -    return 1;
  2337. -}
  2338. -
  2339. -int    lockcount = 0;            /* no. of times we've called lock */
  2340. -
  2341. -#ifdef    VMS
  2342. -
  2343. -#define    SUBLOCK    "/tmp/netnews.lck.1"
  2344. -
  2345. -/*
  2346. - * Newsystem locking.
  2347. - * These routines are different for VMS because we can not
  2348. - * effectively simulate links, and VMS supports multiple
  2349. - * version numbers of files
  2350. - */
  2351. -lock()
  2352. -{
  2353. -    register int i;
  2354. -    register int fd;
  2355. -
  2356. -    if (lockcount++ == 0) {
  2357. -        i = DEADTIME;
  2358. -        while ((fd = creat(SUBLOCK, 0444)) < 0) {
  2359. -            if (--i < 0) {
  2360. -                (void) unlink(SUBLOCK);
  2361. -                logerr("News system locked up");
  2362. -            }
  2363. -            if (i < -3)
  2364. -                xerror("Unable to unlock news system");
  2365. -            sleep((unsigned)1);
  2366. -        }
  2367. -        (void) close(fd);
  2368. -    }
  2369. -}
  2370. -
  2371. -unlock()
  2372. -{
  2373. -    if (--lockcount == 0)
  2374. -        (void) unlink(SUBLOCK); 
  2375. -}
  2376. -
  2377. -#else /* !VMS */
  2378. -
  2379. -/*
  2380. - * Newsystem locking.
  2381. - */
  2382. -
  2383. -#if defined(BSD4_2) || defined(LOCKF)
  2384. -#ifdef LOCKF
  2385. -#include <unistd.h>
  2386. -#else /* !LOCKF */
  2387. -#include <sys/file.h>
  2388. -#endif /* !LOCKF */
  2389. -static int LockFd = -1;
  2390. -lock()
  2391. -{
  2392. -    LockFd = open(SUBFILE,0);
  2393. -    /* This will sleep until the other program releases the lock */
  2394. -    /* We may need to alarm out of this, but I don't think so */
  2395. -#ifdef LOCKF
  2396. -    (void) lockf(LockFd, F_LOCK, 0);
  2397. -#else
  2398. -    (void) flock(LockFd, LOCK_EX);
  2399. -#endif
  2400. -}
  2401. -
  2402. -unlock()
  2403. -{
  2404. -    (void) close(LockFd);
  2405. -}
  2406. -#else /* !BSD4_2 */
  2407. -lock()
  2408. -{
  2409. -    register int i;
  2410. -    extern int errno;
  2411. -
  2412. -    if (lockcount++ == 0) {
  2413. -        i = DEADTIME;
  2414. -        while (link(SUBFILE, LOCKFILE)) {
  2415. -            if (errno != EEXIST)
  2416. -                break;
  2417. -            if (--i < 0)
  2418. -                xerror("News system locked up");
  2419. -            sleep((unsigned)1);
  2420. -        }
  2421. -    }
  2422. -}
  2423. -
  2424. -unlock()
  2425. -{
  2426. -    if (--lockcount == 0)
  2427. -        (void) unlink(LOCKFILE);
  2428. -}
  2429. -#endif /* !BSD4_2 */
  2430. -#endif /* !VMS */
  2431. -
  2432. -/*
  2433. - * Generate the name of the person responsible for posting this article,
  2434. - * in order to check that two articles were posted by the same person.
  2435. - */
  2436. -char *
  2437. -senderof(hp)
  2438. -struct hbuf *hp;
  2439. -{
  2440. -    register char *r, *q, *tp;
  2441. -    char *tailpath();
  2442. -
  2443. -    if (hp->sender[0])
  2444. -        tp = hp->sender;
  2445. -    else if (hp->from[0])
  2446. -        tp = hp->from;
  2447. -    else
  2448. -        tp = tailpath(hp);
  2449. -
  2450. -    /* Remove full name */
  2451. -    q = index(tp, ' ');
  2452. -    if (q)
  2453. -        *q = '\0';
  2454. -
  2455. -    r = AllocCpy(tp);
  2456. -    if (q != NULL)
  2457. -        *q = ' ';
  2458. -    return r;
  2459. -}
  2460. -
  2461. -/* VARARGS1 */
  2462. -error(message, arg1, arg2, arg3)
  2463. -char *message;
  2464. -long arg1, arg2, arg3;
  2465. -{
  2466. -    char buffer[LBUFLEN];
  2467. -
  2468. -    fflush(stdout);
  2469. -    (void) sprintf(buffer, message, arg1, arg2, arg3);
  2470. -    logerr(buffer);
  2471. -    xxit(mode == PROC ? 0 : 1);
  2472. -}
  2473. *-*-END-of-src/ifuncs.c-*-*
  2474. echo x - src/patchlevel.h 1>&2
  2475. sed 's/.//' >src/patchlevel.h <<'*-*-END-of-src/patchlevel.h-*-*'
  2476. -0
  2477. *-*-END-of-src/patchlevel.h-*-*
  2478. echo x - src/localize.sh 1>&2
  2479. sed 's/.//' >src/localize.sh <<'*-*-END-of-src/localize.sh-*-*'
  2480. *-*-END-of-src/localize.sh-*-*
  2481. exit
  2482.  
  2483.